Код: Выделить всё
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme,
options => builder.Configuration.Bind("JwtSettings", options))
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
options => builder.Configuration.Bind("CookieSettings", options));
https://source.dot.net/#microsoft.aspne ... ode]public async Task Invoke(HttpContext context)
{
// ...
var handlers = context.RequestServices.GetRequiredService();
foreach (var scheme in await Schemes.GetRequestHandlerSchemesAsync())
{
var handler = await handlers.GetHandlerAsync(context, scheme.Name) as IAuthenticationRequestHandler;
if (handler != null && await handler.HandleRequestAsync())
{
return;
}
}
var defaultAuthenticate = await Schemes.GetDefaultAuthenticateSchemeAsync();
if (defaultAuthenticate != null)
{
var result = await context.AuthenticateAsync(defaultAuthenticate.Name);
// ...
}
await _next(context);
}
[/code]
Foreach , кажется, применяет схемы Mulitple в первую очередь. Тем не менее, он использует iauthenticationRequestHandler Not IauthenticationHandler .
Поэтому, когда мы называем AddCookie метод расширения, мы добавляем схему типа обработки, чтобы быть CookieAuthenticationHandler (https://source.dot.net/#microsoft.aspne ... ions.cs,81)
и цепочка реализации интерфейса:
Код: Выделить всё
public class CookieAuthenticationHandler : SignInAuthenticationHandler
public abstract class SignInAuthenticationHandler : SignOutAuthenticationHandler, IAuthenticationSignInHandler
// ...
< /code>
SignInAuthenticationHandlerПодробнее здесь: https://stackoverflow.com/questions/774 ... le-schemes
Мобильная версия