如何在 .Net Core 应用程序中从 ADFS 获取 saml 令牌

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

我有一个 .Net 核心微服务。我需要与其他服务交谈以获取数据。但其他服务支持 SAML 身份验证,他们提供 urls(依赖方,adfs)、凭据、证书指纹用于身份验证。如何获得saml令牌?我在下面找到了 .Net 标准的逻辑,但我想要同样的 .net 核心应用程序。

var stsEndpoint = "https://MyAdfsServer/adfs/services/trust/13/UsernameMixed";
var reliantPartyUri = "https://MyDomain/AppRoot/";

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

factory.TrustVersion = System.ServiceModel.Security.TrustVersion.WSTrust13;

// Username and Password here...
factory.Credentials.UserName.UserName = @"Domain\UserName";
factory.Credentials.UserName.Password = "Password";

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

var channel = factory.CreateChannel();
var token = channel.Issue(rst) as GenericXmlSecurityToken;

var saml = token.TokenXml.OuterXml;
.net saml saml-2.0 adfs core
© www.soinside.com 2019 - 2024. All rights reserved.