gpt4 book ai didi

c# - 使用 Active Directory 在 C# 中进行身份验证

转载 作者:太空宇宙 更新时间:2023-11-03 23:39:45 25 4
gpt4 key购买 nike

我正在尝试创建一个需要通过事件目录进行用户身份验证以返回 token 的应用程序,但我不确定如何正确使用它。

我一直在看Authenticate user by ADFS (Active Directory Federation Service)但我不确定如何创建请求安全 token 或如何正确使用它。

是否有可用的可用示例?感谢您的帮助。

最佳答案

这取决于您是否使用 WIF或 .NET 4.5 System.IdentityModel

使用 WIF:

string endpointUri = string.Format("https://{0}/adfs/services/trust/13/usernamemixed", _serverName);

var factory = new Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannelFactory(
new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
new EndpointAddress(endpointUri));

factory.TrustVersion = TrustVersion.WSTrust13;
if (factory.Credentials != null)
{
factory.Credentials.UserName.UserName = "UserName";
factory.Credentials.UserName.Password = "password";
}

var rst = new RequestSecurityToken
{
RequestType = WSTrust13Constants.RequestTypes.Issue,
AppliesTo = new EndpointAddress(_relyingPartyUri),
KeyType = WSTrust13Constants.KeyTypes.Bearer,
};

var channel = factory.CreateChannel();
SecurityToken token = channel.Issue(rst);
return token;

关于c# - 使用 Active Directory 在 C# 中进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29481611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com