Как настроить две схемы аутентификации в AspNetCore 2.0 - PullRequest
0 голосов
/ 17 января 2020

appsettings:

enter image description here

Startup.cs:

enter image description here

Контроллер:

enter image description here

Я добавляю как настройки, но получаю ошибку авторизации, помогите мне?

1 Ответ

1 голос
/ 20 января 2020

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
{
...