使用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 –