.netcore 2.2-身份验证的多方案支持

时间:2019-11-09 18:20:07

标签: authentication asp.net-core .net-core

.netcore 2.2

要使用支持的多种方案(承载,身份,令牌)中的任何一种来认证带有令牌的请求。另外,我们也不想在授权装饰器中添加方案。

在Startup.cs中配置身份验证。

Bearer
Id
Token

在ConfigureServices中

services
.AddAuthentication("Bearer") //fallback default scheme
.AddIdentityServerAuthentication("Bearer", jwtOptions => {
var scopedTokenValidationParameters = services.BuildServiceProvider().GetService();

// to validate based on the requested tenant (having tenant's issue signing key)
jwtOptions.TokenValidationParameters = ScopedTokenValidationParameters;
})
.AddScheme<CustomJwtOptions, CustomJwtHandler>("Id", opts => {})
.AddScheme<CustomTokenOptions, CustomTokenHandler>("Token", opts => {})

在“配置”中,

app.UseAuthentication();

在任何请求上,仅默认方案被调用,其他已注册方案(Id,令牌)处理程序未基于请求的授权方案被调用。

我们有什么遗漏吗?想在这里获得帮助。

谢谢。

0 个答案:

没有答案