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

标签 c# security authentication active-directory

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

相关文章:

c# - 在 RichEditBox UWP 中显示行号

web-services - 使用指定的客户端 key 设计 API

security - 如何禁止 Windows 服务停止

node.js - 登录后在仪表板中显示用户名

authentication - 使用 OAuth 进行服务器到服务器身份验证?

authentication - 基于 token 的身份验证的替代方法

c# - 大约 30 秒后 ActiveMq NMS 断开连接

c# - 在字符串中的某些单词周围注入(inject) HTML 标记

c# - 具有 Type<T> 可为空值的 <T> 类型的类

c - C语言中的asprintf函数,它有什么作用?