AspNetCore 2.0中如何配置两种scheme认证
How to configure two scheme authentication in AspNetCore 2.0
应用程序设置:
Startup.cs:
控制器:
我添加为设置但总是出现授权错误,帮帮我?
Startup.cs 在 ConfigureServices(IServiceCollection 服务)中:
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = "Bearer";
})
.AddOAuthIntrospection("Bearer", o =>
{
o.Authority = new Uri(Configuration["URL"]);
o.Audiences.Add("Audiences");
o.ClientId = Configuration["OpenIdConnectOptions:ClientId"];
o.ClientSecret = Configuration["OpenIdConnectOptions:ClientSecret"];
}).AddOAuthIntrospection("Bearer2", o =>
{
o.Authority = new Uri(Configuration["URL"]);
o.Audiences.Add("Audiences");
o.ClientId = Configuration["OpenIdConnectOptions:ClientId2"];
o.ClientSecret = Configuration["OpenIdConnectOptions:ClientSecret2"];
});
全部在控制器上:
[Authorize(ActiveAuthenticationSchemes = "Bearer,Bearer2")]
[Route("[controller]")]
public class Controller : ControllerBase
{
应用程序设置:
Startup.cs:
控制器:
我添加为设置但总是出现授权错误,帮帮我?
Startup.cs 在 ConfigureServices(IServiceCollection 服务)中:
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = "Bearer";
})
.AddOAuthIntrospection("Bearer", o =>
{
o.Authority = new Uri(Configuration["URL"]);
o.Audiences.Add("Audiences");
o.ClientId = Configuration["OpenIdConnectOptions:ClientId"];
o.ClientSecret = Configuration["OpenIdConnectOptions:ClientSecret"];
}).AddOAuthIntrospection("Bearer2", o =>
{
o.Authority = new Uri(Configuration["URL"]);
o.Audiences.Add("Audiences");
o.ClientId = Configuration["OpenIdConnectOptions:ClientId2"];
o.ClientSecret = Configuration["OpenIdConnectOptions:ClientSecret2"];
});
全部在控制器上:
[Authorize(ActiveAuthenticationSchemes = "Bearer,Bearer2")]
[Route("[controller]")]
public class Controller : ControllerBase
{