我正在尝试创建一个需要通过事件目录进行用户身份验证以返回 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/