使用SAML 2.0协议获取SAML 2.0断言XML

问题描述 投票:0回答:1

我想通过使用SAML 2.0协议而不是WSTrust来获取SAML 2.0令牌。使用ADFS 3.0。是否有任何nuget包或其他库可以实现这一目标?

当前代码使用WSTrust和KERBEROS:

WSTrustChannelFactory trustChannelFactory = null;
var bindingElementCollection = new BindingElementCollection();
    bindingElementCollection.Add(SecurityBindingElement.CreateKerberosOverTransportBindingElement());

    trustChannelFactory = new WSTrustChannelFactory
    (
        new CustomBinding(bindingElementCollection),
        new EndpointAddress(kerberosmixedendpoint)
    );

    trustChannelFactory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;


trustChannelFactory.TrustVersion = TrustVersion.WSTrust13;

var requestSecurityToken = new RequestSecurityToken
{
    RequestType = RequestTypes.Issue,
    AppliesTo = new EndpointReference(Url),
    KeyType = KeyTypes.Bearer,
};   


var channel = (WSTrustChannel)trustChannelFactory.CreateChannel();

var securityToken = await Task<GenericXmlSecurityToken>.Factory.FromAsync(
    channel.BeginIssue, ar =>
    {
        GenericXmlSecurityToken token = null;

        try
        {
            token = channel.EndIssue(ar, out RequestSecurityTokenResponse response)
                as GenericXmlSecurityToken;
        }
        catch (Exception ex)
        {
        }

        return token as GenericXmlSecurityToken;
    },
    requestSecurityToken,
    null
);

result = securityToken?.TokenXml?.OuterXml;

所以我需要得到像这个securityToken?.TokenXml?.OuterXml但使用SAMLP协议的smth。我不能使用WIF,因为它不支持SAML 2.0协议。

c# saml wif
1个回答
0
投票

您可以在项目的下方位置包含可用的代码文件,以访问构建SAML请求,解密和验证SAML响应,读取SAML断言等所需的所有基本方法调用。

https://github.com/onelogin/dotnet-saml/tree/master/App_Code

© www.soinside.com 2019 - 2024. All rights reserved.