public class LocalAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions> | |
{ | |
/// <summary> | |
/// The default user id, injected into the claims for all requests. | |
/// </summary> | |
public static readonly Guid UserId = Guid.Parse("687d7c63-9a15-4faf-af5a-140782baa24d"); | |
/// <summary> | |
/// The name of the authorizaton scheme that this handler will respond to. | |
/// </summary> | |
public const string AuthScheme = "LocalAuth"; | |
private readonly Claim DefaultUserIdClaim = new Claim( | |
UserIdClaimType, UserId.ToString()); | |
public LocalAuthenticationHandler( | |
IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, | |
UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) | |
{ | |
} | |
/// <summary> | |
/// Marks all authentication requests as successful, and injects the | |
/// default company id into the user claims. | |
/// </summary> | |
protected override Task<AuthenticateResult> HandleAuthenticateAsync() | |
{ | |
var authenticationTicket = new AuthenticationTicket( | |
new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { DefaultUserIdClaim }, AuthScheme)), | |
new AuthenticationProperties(), | |
AuthScheme); | |
return Task.FromResult(AuthenticateResult.Success(authenticationTicket)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment