Created
November 27, 2018 19:35
-
-
Save michaeltnguyen/718f801fba2fdf370e2e8c5a5e763e08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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