using System.Security.Claims; using System.Text.Encodings.Web; using Bifrost.Web.Features.Membership; using Microsoft.AspNetCore.Authentication; using Microsoft.Extensions.Options; using Microsoft.Extensions.Logging; namespace Bifrost.Web.Tests.Support; public sealed class TestAuthHandler( IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder) : AuthenticationHandler(options, logger, encoder) { public const string SchemeName = "Test"; protected override Task HandleAuthenticateAsync() { if (Request.Headers.ContainsKey("X-Test-Anonymous")) { return Task.FromResult(AuthenticateResult.NoResult()); } var claims = new[] { new Claim(ClaimTypes.NameIdentifier, "12345"), new Claim(ClaimTypes.Name, "test-admin"), new Claim(BifrostClaimTypes.GitHubLogin, "test-admin"), new Claim(BifrostClaimTypes.DisplayName, "Test Admin") }; var identity = new ClaimsIdentity(claims, SchemeName); var principal = new ClaimsPrincipal(identity); var ticket = new AuthenticationTicket(principal, SchemeName); return Task.FromResult(AuthenticateResult.Success(ticket)); } }