Security 在TokenValidationParameters中,我可以在哪里指定JWT令牌中的算法应该与HS256匹配?
我正在使用AspNet核心构建一个web api和JWT令牌来验证用户 我在哪里可以在Security 在TokenValidationParameters中,我可以在哪里指定JWT令牌中的算法应该与HS256匹配?,security,asp.net-core,.net-core,jwt,Security,Asp.net Core,.net Core,Jwt,我正在使用AspNet核心构建一个web api和JWT令牌来验证用户 我在哪里可以在TokenValidationParameters中指定令牌中的alg应该匹配HS256(并且从不none) 库是否默认拒绝alg设置为none的传入令牌?根据默认中间件不允许“alg”:“none”。似乎这是由于在报告中提到的漏洞 services .AddAuthentication(options => { options.Defaul
TokenValidationParameters
中指定令牌中的alg
应该匹配HS256(并且从不none
)
库是否默认拒绝alg
设置为none
的传入令牌?根据默认中间件不允许“alg”:“none”
。似乎这是由于在报告中提到的漏洞
services
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(cfg =>
{
cfg.RequireHttpsMetadata = false;
cfg.SaveToken = true;
string jwtIssuer = configuration["JwtIssuer"];
SymmetricSecurityKey securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JwtKey"]));
cfg.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuer = jwtIssuer,
ValidAudience = jwtIssuer,
ValidateIssuerSigningKey = true,
IssuerSigningKey = securityKey,
ClockSkew = TimeSpan.Zero
};
});
关于拒绝:我尝试使用“alg”传递令牌:“无”
,并在响应中获得无效的\u令牌(Microsoft.AspNetCore.Authentication.JwtBearer 2.1.0
)
顺便说一下,HS256
和无算法的规范实现。这方面运气好吗?