System.IdentityModel.Tokens.Jwt 的更新导致 IdentityServer3 客户端发生重大变化

Update of System.IdentityModel.Tokens.Jwt causing breaking change in IdentityServer3 Client

希望是一个容易解决的问题。

Microsoft 的 System.IdentityModels.Tokens.Jwt 包昨天在 NuGet 上从 4.0.2.206211351 更新到 v5.0。不幸的是,这导致了一些 "standard" IdentityServer3 代码的重大变化。即取自他们的代码示例,所以我想很多开发人员可能会在未来几天看到这个问题。

原代码

使用 v4.0.2.xxxxxx 版本的包。我有

using System.IdentityModel.Tokens;

在命名空间中。

然后在配置方法中开始为:

public void Configuration(IAppBuilder app)
    {
        AntiForgeryConfig.UniqueClaimTypeIdentifier = "sub";

        JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = "Cookies"
        });

        app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        { ... };

更新后

更新配置行后:

JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

导致问题。

第一件事是 Class 显然已经移入 System.IdentityModel.Tokens.Jwt 命名空间,解决起来还不错。

但是,我现在在 JwtSecurityTokenHandler.InboundClaimTypeMap 上收到 Object reference required for a non-static field 错误。

我是不是遗漏了什么,另一个库是必需的,还是在调用 Startup.Configuration() 之前发生了什么需要深入研究的事情?

当你去看医生时说 "it always hurts when I do this" - 医生会回复 "then stopping doing this" ;)

v4 -> v5 根据定义是一个重大变化。您需要 v5 吗?

也就是说 - 一个简单的智能感知探索会发现他们将 InboundClaimTypeMap 重命名为 DefaultInboundClaimTypeMap

为沿途的更多重大变化做好准备。

OWIN 中的访问令牌验证与 system.identitymodel v5 不兼容 - 您需要降级到 v4 - See issue here