【问题标题】:No valid key mapping found for securityToken: 'System.IdentityModel.Tokens.X509SecurityToken' and issuer找不到 securityToken 的有效密钥映射:“System.IdentityModel.Tokens.X509SecurityToken”和颁发者
【发布时间】:2017-08-17 14:00:50
【问题描述】:

我正在使用 ADFS 的 IDP 页面进行 ADFS 身份验证。

我能够成功重定向到 IDP 页面,也能够在通过身份验证后成功重定向回我的应用程序。

返回应用程序后,我收到以下错误消息:

未找到 securityToken 的有效密钥映射: 'System.IdentityModel.Tokens.X509SecurityToken' 和颁发者

我在 web.config 文件中添加了以下代码来解密索赔信息。

 <authority name="http://idp.neuronetics.com/adfs/services/trust">
          <keys>
            <add thumbprint="‎‎1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234"/>
          </keys>`enter code here
          <validIssuers>
            <add name="http://adfsServiceDomain/adfs/services/trust" />
          </validIssuers>
        </authority>

我查看了许多与此相关的文章。大多数文章都建议验证ADFS的令牌签名证书的指纹。

我已经仔细检查过,指纹是完美的。

有人对这个问题有任何想法吗?

请指教。

如果您有任何疑虑或疑问或需要更多信息,请告诉我。

【问题讨论】:

  • 您使用的是 OWIN Ws-Fed 还是 WIF?
  • 我正在使用 Ws-Fed
  • 我知道,问题是你用的是OWIN还是WIF。
  • 我没有使用 Owin。只是普通的WIF。我知道 Owin 直接从 Federation xml 文件中获取指纹,但它与我的系统不兼容。所以我使用的是普通的 WIF。
  • 好的,我提供了答案。

标签: asp.net authentication saml adfs ws-federation


【解决方案1】:

由于您使用的是 WIF 而不是 OWIN,因此您几乎可以覆盖默认的颁发者注册表并提供您自己的注册表,以便您更好地控制接受哪些颁发者。

覆盖颁发者注册表涉及提供一个继承自 IssuerNameRegistry 的类

public class CustomIssuerNameRegistry : IssuerNameRegistry
{
    public override string GetIssuerName( SecurityToken securityToken )
    {
        X509SecurityToken x509Token = securityToken as X509SecurityToken;
        if ( x509Token != null &&
             x509Token.Certificate != null
            )
        {
            // this is where you validate the certificate programatically
            // for example, you can verify the thumbprint against
            // a list of accepted thumprints

            // return a string, the name of the issuer to indicate
            // succesfull validation
            return "issuer name";
        }

        throw new SecurityTokenException( "Untrusted issuer." );
    }

并在web.config 的 WIF 管道中注册颁发者注册表

<system.identityModel>
  <identityConfiguration>
    <issuerNameRegistry type="Namespace.CustomIssuerNameRegistry, AssemblyName" />
  </identityConfiguration>
</system.identityModel>

这种方法可以让您彻底调试传入令牌的证书。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多