使用ASP.NET Core 1.0(rtm),我生成了minimal verifiable sample,我看到我生成的JSON Web令牌不是经过.NET核心JSON网络令牌中间件要求的挑战,以及与此错误是失败:UseJwtBearerAuthentication失败,IDX10504:无法验证签名,令牌没有签名
Microsoft.IdentityModel.Tokens.SecurityTokenInvalidSignatureException:
IDX10504: Unable to validate signature, token does not have a signature:
'... ... token value here...'
我已经产生了最小的样品,其曾在ASP.NET核心RC1罚款,但不工作的RTM 。我没有移植到RC2进行测试,但我相信这样的测试毫无意义。您可以通过提供的测试脚本行使演示:
python tests\testloginapi.py
GET OK: 200 http://localhost:54993/authorize/login?username=TEST&pas...
POST OK: 200 http://localhost:54993/authorize/login?username=TEST&pas...
authorization token received... eyJhbGciOi...
expected status 200 but got 401 for GET http://localhost:54993/authorizetest/test
我的小例子的突出要点是:
Startup.cs方法配置有:
app.UseJwtBearerAuthentication(_keyArtifacts.getJwtBearerOptions());
承载选项都是这样:
public static JwtBearerOptions CreateJwtBearerOption(RsaSecurityKey key, string tokenIssuer, string tokenAudience)
{
var jwtBearerOptions = new JwtBearerOptions();
jwtBearerOptions.AutomaticAuthenticate = true;
jwtBearerOptions.AutomaticChallenge = true;
jwtBearerOptions.TokenValidationParameters.ValidateIssuerSigningKey = true;
jwtBearerOptions.TokenValidationParameters.IssuerSigningKey = key;
jwtBearerOptions.TokenValidationParameters.ValidIssuer = tokenIssuer;
jwtBearerOptions.TokenValidationParameters.ValidateIssuer = true;
jwtBearerOptions.TokenValidationParameters.ValidateLifetime = true;
jwtBearerOptions.TokenValidationParameters.ClockSkew = TimeSpan.Zero;
jwtBearerOptions.TokenValidationParameters.ValidAudience = tokenAudience;
return jwtBearerOptions;
}
这个问题真的可以归结为:
在Asp.net核心1.0 rtm中,创建通过中间件挑战的令牌的最小步骤是什么?
我,我只是缺少一些简单的步骤(如为一个小行代码也许),这将使这个演示的工作,其中包括有“签约”的工作?
鉴于demo仍然是一段可怕的代码,并且没有人应该在生产中使用它(因为我已经为此感到羞愧),我希望这个问题仍然可以阐明如何使至少在演示范围内,
UseJwtBearerAuthentication
系统实际上工作。
有用的信息:https://stormpath.com/blog/token-authentication-asp-net-core –