Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 将IdentityServer4升级到Core 3.1-令牌突然没有正确签名?_Asp.net Core_Oauth 2.0_Identityserver4_Openid Connect - Fatal编程技术网

Asp.net core 将IdentityServer4升级到Core 3.1-令牌突然没有正确签名?

Asp.net core 将IdentityServer4升级到Core 3.1-令牌突然没有正确签名?,asp.net-core,oauth-2.0,identityserver4,openid-connect,Asp.net Core,Oauth 2.0,Identityserver4,Openid Connect,将IdentityServer4(2.5.3-3.1.0)升级到Core 3.1(从2.2)时遇到错误。突然,发行的代币没有正确的签名。我们没有改变签名算法;版本之间仍使用相同的.PFX证书 var idSrvBuilder = services.AddIdentityServer(opts => { opts.Events.RaiseErrorEvents = true; opts.Events.Ra

将IdentityServer4(2.5.3-3.1.0)升级到Core 3.1(从2.2)时遇到错误。突然,发行的代币没有正确的签名。我们没有改变签名算法;版本之间仍使用相同的.PFX证书

var idSrvBuilder = services.AddIdentityServer(opts =>
            {
                opts.Events.RaiseErrorEvents = true;
                opts.Events.RaiseFailureEvents = true;
                opts.Events.RaiseInformationEvents = true;
                opts.Events.RaiseSuccessEvents = true;
                if (_env.IsProduction())
                {
                    opts.PublicOrigin = Configuration["Globals:IdentityURL"];
                }
            }).AddSigningCredential(new X509Certificate2(Configuration["Cert:Path"], Configuration["Cert:Password"]));
当对旧API使用OWIN中间件“UseIdentityServerBealerTokenauthentication”时,如果
ValidationMode
Local
则会失败,但如果它直接针对IdentityServer进行验证则不会失败(使用
ValidationMode
)。API将只返回“Unauthorized”,但使用较旧的令牌(相同的证书对其进行签名!)

看看不同版本之间发行的代币,有一个明显的区别:

旧的(已卸下的有效载荷):

使用以下令牌头:

{
  "alg": "RS256",
  "kid": "6B138EB31A89A1A7DA7B6DF73094F323DBE78B66",
  "typ": "JWT",
  "x5t": "axOOsxqJoafae233MJTzI9vni2Y"
}
新的:

具有以下标题:

{
  "alg": "RS256",
  "kid": "6B138EB31A89A1A7DA7B6DF73094F323DBE78B66",
  "typ": "at+jwt",
  "x5t": "axOOsxqJoafae233MJTzI9vni2Y"
}
我猜问题在于新令牌中的
“typ”
“at+jwt”
?这是什么意思?我看过IdentityServer的发行版、Github的问题、谷歌搜索的stackoverflow,但似乎没有人注意到神秘的新
“at+jwt”
“typ”


这可能是问题的根源吗?我如何指导我的新版本发布标准JWT?在+jwt上的这个奇怪的
是什么?

感谢@Ruard van Elburg在注释中链接到显式类型的令牌

将默认的“at+jwt”更改为“jwt”解决了这个问题:

var idSrvBuilder = services.AddIdentityServer(opts =>
            {
                opts.Events.RaiseErrorEvents = true;
                opts.Events.RaiseFailureEvents = true;
                opts.Events.RaiseInformationEvents = true;
                opts.Events.RaiseSuccessEvents = true;
                opts.AccessTokenJwtType = "jwt";
                if (_env.IsProduction())
                {
                    opts.PublicOrigin = Configuration["Globals:IdentityURL"];
                }
            });
我猜根本的问题在于我们在API中使用的包
IdentityServer3.AccessTokenValidation
无法识别at+jwt。我们使用它是为了潜在地支持引用令牌

我们也无法将此API升级到ASP Core并使用Microsoft提供的较新的
IdentityServerAuthenticationExtensions
,因为我们需要支持的某些第三方的依赖关系。这个包似乎能够在+jwt下处理

编辑:

还是不行。查看了Ruard链接到的Github问题

事实证明,我还必须打开EmitLegacyResourceAudienceClaim,所以看起来不是这样的:

var idSrvBuilder = services.AddIdentityServer(opts =>
            {
                opts.Events.RaiseErrorEvents = true;
                opts.Events.RaiseFailureEvents = true;
                opts.Events.RaiseInformationEvents = true;
                opts.Events.RaiseSuccessEvents = true;
                opts.AccessTokenJwtType = "JWT";
                opts.EmitLegacyResourceAudienceClaim = true;
                if (_env.IsProduction())
                {
                    opts.PublicOrigin = Configuration["Globals:IdentityURL"];
                }
            })

这就是所谓的。您可以通过使用重写该值来禁用此行为。谢谢!似乎已经解决了这个问题。另外,刚刚发现了这个。事实上,我怀疑它更深一层。AccessTokenValidation包调用而不指定类型。JwtFormat然后设置验证的参数:
\u validationParameters.AuthenticationType=“JWT”。似乎没有解决此问题。我忘记将ValidationMode更改为“Local”或“Both”,我们立即得到“此请求的授权已被拒绝”尝试更改签名密钥,但也不起作用。在我的情况下,此解决方案有效!非常感谢你!是否可以以某种方式将其标记为答案?现在,IdentityServer4将更改为EmitStaticAudienceClaim,而不是EmitLegacyResourceAudienceClaim。
{
  "alg": "RS256",
  "kid": "6B138EB31A89A1A7DA7B6DF73094F323DBE78B66",
  "typ": "at+jwt",
  "x5t": "axOOsxqJoafae233MJTzI9vni2Y"
}
var idSrvBuilder = services.AddIdentityServer(opts =>
            {
                opts.Events.RaiseErrorEvents = true;
                opts.Events.RaiseFailureEvents = true;
                opts.Events.RaiseInformationEvents = true;
                opts.Events.RaiseSuccessEvents = true;
                opts.AccessTokenJwtType = "jwt";
                if (_env.IsProduction())
                {
                    opts.PublicOrigin = Configuration["Globals:IdentityURL"];
                }
            });
var idSrvBuilder = services.AddIdentityServer(opts =>
            {
                opts.Events.RaiseErrorEvents = true;
                opts.Events.RaiseFailureEvents = true;
                opts.Events.RaiseInformationEvents = true;
                opts.Events.RaiseSuccessEvents = true;
                opts.AccessTokenJwtType = "JWT";
                opts.EmitLegacyResourceAudienceClaim = true;
                if (_env.IsProduction())
                {
                    opts.PublicOrigin = Configuration["Globals:IdentityURL"];
                }
            })