【问题标题】:Deserializing Claims from RSTR token using WIF使用 WIF 从 RSTR 令牌反序列化声明
【发布时间】:2011-10-01 02:11:03
【问题描述】:

我正在构建自己的 STS,它处理不同类型的协议(WS-Federation、OAuth 等)。我在处理 ADFS 2 发布到我的 STS 的 RSTR 令牌时遇到了困难。

我已成功反序列化声明的代码,但是我必须添加部分 microsoft.identityModel 配置部分才能使其正常工作,并且我需要在 Trusted People 存储中添加 ADFS 2 签名证书。

我有自己的配置部分,我在其中指定内容,因此使用 microsoft.identityModel 是多余的。

代码:

    var request = System.Web.HttpContext.Current.Request;

    var message = SignInResponseMessage.CreateFromFormPost(request) as SignInResponseMessage;

    var rstr = new WSFederationSerializer().CreateResponse(message, new WSTrustSerializationContext());

    var serviceConfig = new ServiceConfiguration();

    IClaimsIdentity claimsIdentity = null;
    using (var reader = XmlReader.Create(
                                new StringReader(rstr.RequestedSecurityToken.SecurityTokenXml.OuterXml)))
    {
        var token = serviceConfig.SecurityTokenHandlers.ReadToken(reader);
        claimsIdentity = serviceConfig.SecurityTokenHandlers.ValidateToken(token).FirstOrDefault();
    }

    return claimsIdentity;

我想避免的必要配置:

<microsoft.identityModel>
    <service>
      <audienceUris mode="Never">
      </audienceUris>
      <issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
        <trustedIssuers>
          <add thumbprint="27d3db77a9716ad370a7e9c632d5b98dcc5b1479" name="https://UrlToAdfs/adfs/ls/" />
        </trustedIssuers>
      </issuerNameRegistry>
    </service>
  </microsoft.identityModel>

【问题讨论】:

    标签: wif saml adfs2.0


    【解决方案1】:

    在代码中实现这一点的方法是派生您自己的 IssuerNameRegistry 实现并将其应用到您的 STS:

    SecurityTokenService.SecurityTokenServiceConfiguration.IssuerNameRegistry

    顺便说一句,您是否检查过 Azure 访问控制服务 (http://acs.codeplex.com/)?

    【讨论】:

    • 就是这样,虽然我仍然需要在配置中指定它是可以的。我见过 Azure ACS,我必须说它有一些很棒的功能。问题是我们正在研究创建自己的 STS 有多难。感谢您的帮助。
    猜你喜欢
    • 2012-04-08
    • 1970-01-01
    • 2015-03-25
    • 2020-12-12
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 2017-09-28
    • 2021-04-30
    相关资源
    最近更新 更多