chore: remove OpenApi and configure JWT authentication schemes

This commit is contained in:
Stevan Freeborn
2026-02-03 11:06:44 -06:00
parent 1221d971a6
commit d1a4de8fdb
5 changed files with 40 additions and 3 deletions
@@ -1,3 +1,5 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
namespace FiscalOS.Infra.Authentication;
public sealed record JwtOptions
@@ -6,6 +8,8 @@ public sealed record JwtOptions
public string Audience { get; init; } = string.Empty;
public string Secret { get; init; } = string.Empty;
public int ExpiryInMinutes { get; init; } = 5;
public SymmetricSecurityKey Key => new(Encoding.UTF8.GetBytes(Secret));
}
public sealed record JwtOptionsSetup : IConfigureOptions<JwtOptions>
@@ -22,4 +26,33 @@ public sealed record JwtOptionsSetup : IConfigureOptions<JwtOptions>
{
_configuration.GetSection(SectionName).Bind(options);
}
}
public sealed class JwtBearerOptionsSetup(IOptions<JwtOptions> jwtOptions) : IConfigureNamedOptions<JwtBearerOptions>
{
private readonly JwtOptions _jwtOptions = jwtOptions.Value;
public void Configure(string? name, JwtBearerOptions options)
{
options.TokenValidationParameters = new()
{
ValidIssuer = _jwtOptions.Issuer,
ValidAudience = _jwtOptions.Audience,
IssuerSigningKey = _jwtOptions.Key,
ValidateIssuer = true,
ValidateAudience = true,
ValidateIssuerSigningKey = true,
ValidateLifetime = true,
};
if (name is Schemes.AllowExpiredTokens)
{
options.TokenValidationParameters.ValidateLifetime = false;
}
}
public void Configure(JwtBearerOptions options)
{
Configure(Options.DefaultName, options);
}
}