【问题标题】:Is there any way I can support JWTSecurityTokenHandler on WIF 4.5?有什么方法可以在 WIF 4.5 上支持 JWTSecurityTokenHandler 吗?
【发布时间】:2017-03-09 04:49:57
【问题描述】:

我想在我的使用 WIF 4.5 的 WebAPI 应用程序上支持 JWT(Json Web Token)。

我正在使用System.IdentityModel.Tokens.Jwt 5.0.0 nuget 包,它有一个JWTSecurityTokenHandler,似乎与旧版本的WIF 集成。

问题是处理程序派生Microsoft.IdentityModel.Tokens.SecurityTokenHandler,而不是像配置部分所期望的那样从System.IdentityModel.Tokens.SecurityTokenHandler

因此我得到了一个可以理解的异常:

Parser Error Message: ID1029: The custom type is not suitable because it does not extend the correct base class.
CustomType: 'System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler, System.IdentityModel.Tokens.Jwt, Version=5.0.0.127, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
BaseClass: 'System.IdentityModel.Tokens.SecurityTokenHandler'

我的配置如下:

<system.identityModel>
        <identityConfiguration>
            <audienceUris>
                <add value="http://localhost:49482/" />
            </audienceUris>
            <securityTokenHandlers>
                <add type="System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler, System.IdentityModel.Tokens.Jwt" />
                <securityTokenHandlerConfiguration>
                    <certificateValidation certificateValidationMode="PeerTrust" />
                </securityTokenHandlerConfiguration>
            </securityTokenHandlers>
        </identityConfiguration>
</system.identityModel>

如何在 WIF 4.5 上支持 JWT?有什么办法可以使用这个包来做到这一点?我做错了吗?

【问题讨论】:

    标签: c# asp.net-web-api jwt wif


    【解决方案1】:

    这个包是针对 .net 标准 1.4 编写的,它不包含 System.IdentityModel API,因此该包没有与 WIF 集成。

    基于https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/94,如果你想通过 WIF 配置使用 System.IdentityModel,你需要回到包的 3.x 版本。

    当然,您当然可以编写自己的 System.IdentityModel.Tokens.SecurityTokenHandler 实现来包装 Microsoft.IdentityModel.Tokens.SecurityTokenHandle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      相关资源
      最近更新 更多