【问题标题】:active client - get token from resource partner adfs using idp token活动客户端 - 使用 idp 令牌从资源合作伙伴 adfs 获取令牌
【发布时间】:2013-04-26 08:27:15
【问题描述】:

我正在尝试使用以下场景编写控制台应用程序: 客户端首先从身份提供者请求令牌,然后使用此令牌从资源 STS 请求新令牌 使用以下链接:http://leastprivilege.com/2010/10/28/wif-adfs-2-and-wcfpart-6-chaining-multiple-token-services/

我设法从 Idp 获取令牌,但没有设法从 Resource STS 获取令牌。

这是我的代码:

    string RPRealm = "https://service.contoso.com/";
    string RSTSRealm = "http://fsweb.contoso.com/adfs/services/trust";
    string IdPstsEndpoint = "https://IdpAdfs.domain.com/adfs/services/trust/13/kerberosmixed";
    string RSTSEndpoint = "https://fsweb.contoso.com/adfs/services/trust/13/IssuedTokenMixedSymmetricBasic256";

    private static SecurityToken GetIdPToken(string rstsRealm, string IdPstsEndpoint)
    {
        using (var factory = new WSTrustChannelFactory(
                new KerberosWSTrustBinding(SecurityMode.TransportWithMessageCredential),
                new EndpointAddress(new Uri(IdPstsEndpoint))))
        {
            WSTrustChannel channel = null;
            factory.TrustVersion = TrustVersion.WSTrust13;
            try
            {
                var rst = new RequestSecurityToken
                {
                    RequestType = WSTrust13Constants.RequestTypes.Issue,
                    AppliesTo = new EndpointAddress(rstsRealm),
                    KeyType = WSTrust13Constants.KeyTypes.Bearer,
                };

                channel = (WSTrustChannel)factory.CreateChannel();
                RequestSecurityTokenResponse rstr;
                SecurityToken token = channel.Issue(rst, out rstr);
                return token;
            }
            finally
            {
                if (channel != null)
                {
                    channel.Abort();
                }

                factory.Abort();
            }
        }
    }


private static SecurityToken GetRSTSToken(SecurityToken IdPToken, string RSTSEndpoint, string RPRealm)
{
   var binding = new WS2007FederationHttpBinding();
   binding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey;
   binding.Security.Message.EstablishSecurityContext = false;
   binding.Security.Mode = WSFederationHttpSecurityMode.TransportWithMessageCredential;

    using (var factory = new WSTrustChannelFactory(
           binding,
            new EndpointAddress(new Uri(RSTSEndpoint))))
    {
        var rst = new RequestSecurityToken
        {
            RequestType = WSTrust13Constants.RequestTypes.Issue,
            AppliesTo = new EndpointAddress(RPRealm),
            KeyType = WSTrust13Constants.KeyTypes.Bearer,
        };
        factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
        factory.TrustVersion = TrustVersion.WSTrust13;
        factory.Credentials.SupportInteractive = false;
        factory.ConfigureChannelFactory();


        var channel = factory.CreateChannelWithIssuedToken(IdPToken);
        RequestSecurityTokenResponse rstr;
        SecurityToken token = channel.Issue(rst, out rstr);
        return token;
    }
}

我收到此错误: 响应消息的内容类型 text/html 与绑定的内容类型不匹配(application/soap+xml; charset=utf-8) 我的代码有什么问题? 提前致谢

【问题讨论】:

  • 尝试在 Thinktecture.IdentityModel 中使用 WSTrust-Bindings - 例如对于第二跳,使用 IssuedTokenWSTrustBinding。
  • 如果我使用 IssuedTokenWSTrustBinding,我得到错误:签名令牌通用 XML 令牌:validFrom:05/05/2013 14:51:22 validTo:05/05/2013 15:51:22 InternalTokenReference: SamlAssertionKeyIdentifierClause(AssertionId = '_29979767-107a-4c16-b59b-4a9462edfea3') ExternalTokenReference:SamlAssertionKeyIdentifierClause(AssertionId = '_29979767-107a-4c16-b59b-4a9462edfea3') Token Element: (Encryptededfea3')安全令牌在需要它执行加密操作的上下文中使用,但令牌不包含加密...

标签: c# wcf saml claims-based-identity adfs2.0


【解决方案1】:

ADFS 在其联合端点上不支持不记名令牌。换句话说,在您的第一个跃点上,您需要在 RST 上指定 KeyTypes.Symmetric。

【讨论】:

    猜你喜欢
    • 2018-05-10
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 2021-08-26
    • 1970-01-01
    相关资源
    最近更新 更多