/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Mvc/test/WebSites/BasicWebSite/BasicAuthenticationHandler.cs
39 строк
1 KB
Chris Ross
Obsolete and replace ISystemClock in Security, Identity #47472 (#47717)
26 апр 2023, 05:02
Не верифицирован
26 апр 2023, 05:02
726f467
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Security.Claims; using System.Text.Encodings.Web; using Microsoft.AspNetCore.Authentication; using Microsoft.Extensions.Options; namespace BasicWebSite; public class BasicAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions> { public BasicAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder) : base(options, logger, encoder) { } protected override Task<AuthenticateResult> HandleAuthenticateAsync() { if (!Request.Headers.ContainsKey("Authorization")) { return Task.FromResult(AuthenticateResult.NoResult()); } var principal = new ClaimsPrincipal(); principal.AddIdentity(new ClaimsIdentity( new[] { new Claim("Manager", "yes"), new Claim(ClaimTypes.Role, "Administrator"), new Claim(ClaimTypes.NameIdentifier, "John") }, Scheme.Name)); return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket( principal, new AuthenticationProperties(), Scheme.Name))); } }