c# - 使用 Windows 直通身份验证检索依赖方信任的 SAML 令牌
问题描述
我正在尝试确定一种应用程序检索 SAML 令牌以代表应用程序的当前上下文(作为用户)访问依赖方信任的方法。
常见的建议是使用 WSTrustChannelFactory 但提供用户名和密码来检索 SAML 令牌。我不想这样做,所以它对用户来说是无缝的。我觉得 ADFS 应该支持此请求的 SSO 身份验证(使用直通 Windows 身份验证)。这可能吗?
这是需要凭据的典型推荐代码:
public SecurityToken GetSamlToken()
{
using (var factory = new WSTrustChannelFactory(
new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
new EndpointAddress(new Uri("https://serv/adfs/services/trust/13/usernamemixed"))))
{
factory.Credentials.UserName.UserName = "username";
factory.Credentials.UserName.Password = "password";
factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
factory.TrustVersion = TrustVersion.WSTrust13;
WSTrustChannel channel = null;
try
{
string KeyType;
var rst = new RequestSecurityToken
{
RequestType = WSTrust13Constants.RequestTypes.Issue,
AppliesTo = new EndpointAddress("net.tcp://localhost:xxxx/Service1/mex"),
KeyType = Microsoft.IdentityModel.Protocols.WSTrust.WSTrust13Constants.KeyTypes.Bearer,
};
channel = (WSTrustChannel)factory.CreateChannel();
return channel.Issue(rst);
}
finally
{
if (channel != null)
{
channel.Abort();
}
factory.Abort();
}
}
}
谢谢您的帮助!
解决方案
推荐阅读
- azure - 作为数组复制()的参数在资源中不起作用
- python - 将字符串从列表插入数据框公式以在熊猫中循环计算
- swift - 虽然我做了可选绑定,但我收到错误“致命错误:在展开可选值时意外发现 nil”
- google-bigquery - 是否可以在 BigQuery 网络控制台中设置默认区域?
- mongodb - 使用 Azure Cosmos DB 的 Hangfire
- dart - 需要在 Flutter web view 中使用 src 通过 HTML 添加图片资源
- python - 我不能使用 Pip 在 Windows 中安装软件包
- django - 如何将三个或多个参数传递给自定义模板标签过滤器 django?
- javascript - 过滤后下拉 DOM 不更新
- javascript - Node/Express - res.status().send() 只发送状态但不发送对象