Add AD auth and B1 currency fields
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System.Security.Claims;
|
||||
using System.Text.Encodings.Web;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace TrafagSalesExporter.Security;
|
||||
|
||||
public sealed class DevelopmentAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
|
||||
{
|
||||
public const string SchemeName = "Development";
|
||||
public const string AdminClaimType = "TrafagSalesExporter.Admin";
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public DevelopmentAuthenticationHandler(
|
||||
IOptionsMonitor<AuthenticationSchemeOptions> options,
|
||||
ILoggerFactory logger,
|
||||
UrlEncoder encoder,
|
||||
IConfiguration configuration)
|
||||
: base(options, logger, encoder)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||
{
|
||||
var settings = _configuration.GetSection(SecurityOptions.SectionName).Get<SecurityOptions>() ?? new SecurityOptions();
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new(ClaimTypes.Name, settings.DevelopmentUserName),
|
||||
new(ClaimTypes.NameIdentifier, settings.DevelopmentUserName)
|
||||
};
|
||||
|
||||
if (settings.DevelopmentUserIsAdmin)
|
||||
claims.Add(new Claim(AdminClaimType, "true"));
|
||||
|
||||
var identity = new ClaimsIdentity(claims, SchemeName);
|
||||
var principal = new ClaimsPrincipal(identity);
|
||||
var ticket = new AuthenticationTicket(principal, SchemeName);
|
||||
|
||||
return Task.FromResult(AuthenticateResult.Success(ticket));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user