37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using DexDemoBackend;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using System.Security.Claims;
|
|
using Microsoft.Extensions.Options;
|
|
using System.Text.Encodings.Web;
|
|
|
|
public class InsecureDevAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
|
|
{
|
|
private readonly AppConfig _config;
|
|
|
|
public InsecureDevAuthenticationHandler(
|
|
IOptionsMonitor<AuthenticationSchemeOptions> options,
|
|
ILoggerFactory logger,
|
|
UrlEncoder encoder,
|
|
AppConfig config) : base(options, logger, encoder)
|
|
{
|
|
_config = config;
|
|
}
|
|
|
|
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
|
|
{
|
|
var email = _config.InsecureDevEmail ?? "dev@example.com";
|
|
|
|
var claims = new[]
|
|
{
|
|
new Claim(ClaimTypes.Name, email),
|
|
new Claim(_config.EmailClaimType, email)
|
|
};
|
|
|
|
var identity = new ClaimsIdentity(claims, Scheme.Name);
|
|
var principal = new ClaimsPrincipal(identity);
|
|
var ticket = new AuthenticationTicket(principal, Scheme.Name);
|
|
|
|
return Task.FromResult(AuthenticateResult.Success(ticket));
|
|
}
|
|
}
|