Compare commits

...

7 Commits

Author SHA1 Message Date
khwezi 84d33d3607 Merge pull request 'Refactored authentication' (#71) from payments into master
Reviewed-on: #71
2026-06-04 08:48:15 +02:00
Khwezi Mngoma 8f97d7cf38 Refactored authentication
continuous-integration/drone/pr Build is passing
2026-06-04 08:47:18 +02:00
khwezi f51cc03327 Merge pull request 'Disabled caching' (#70) from payments into master
Reviewed-on: #70
2026-06-03 17:49:04 +02:00
Khwezi Mngoma 652ca82a57 Disabled caching
continuous-integration/drone/pr Build is passing
2026-06-03 17:48:38 +02:00
khwezi aff6fcabf4 Merge pull request 'payments' (#69) from payments into master
Reviewed-on: #69
2026-06-03 17:38:45 +02:00
Khwezi Mngoma a50830ffaa Refactored auth
continuous-integration/drone/pr Build is passing
2026-06-03 17:37:56 +02:00
Khwezi Mngoma ee6f8a283e Refactored oauth registration 2026-06-03 17:37:33 +02:00
6 changed files with 25 additions and 18 deletions
+1
View File
@@ -363,3 +363,4 @@ MigrationBackup/
FodyWeavers.xsd
/LiteCharms.Features.Tests/http/http-client.env.json
/LiteCharms.Features.Tests/http/midrandshop-api/http-client.env.json
/LiteCharms.Features.Tests/http/authentik/http-client.env.json
@@ -1,6 +1,6 @@
{
"FeatureManagement": {
"CategorySeederService": true,
"CategorySeederService": false,
"CustomerSeederService": false,
"ProductsSeederService": false
},
@@ -0,0 +1,6 @@
### Authentik Token Request (Service Account Explicit)
POST {{authority}}
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: identity
grant_type={{grantType}}&client_id={{clientId}}&username={{username}}&password={{password}}&scope={{scope}}
@@ -4,6 +4,8 @@ public sealed class AuthentikSettings
{
public string? Authority { get; set; }
public string? IntrospectionUrl { get; set; }
public string? ApiResourceName { get; set; }
public string? ApiResourceSecret { get; set; }
@@ -13,6 +15,4 @@ public sealed class AuthentikSettings
public string? RequiredClaimNameValue { get; set; }
public bool RequireHttpsMetadata { get; set; }
public bool BypassSslErrors { get; set; }
}
+14 -14
View File
@@ -11,28 +11,28 @@ public static class Api
public static IServiceCollection AddAuthentic(this IServiceCollection services, IConfiguration configuration)
{
var configSection = configuration.GetSection(nameof(AuthentikSettings));
var authOptions = new AuthentikSettings();
configSection.Bind(authOptions);
configuration.GetSection("Authentik").Bind(authOptions);
services.Configure<AuthentikSettings>(configuration.GetSection(nameof(AuthentikSettings)));
services.Configure<AuthentikSettings>(configSection);
services.AddAuthentication(OAuth2IntrospectionDefaults.AuthenticationScheme)
.AddOAuth2Introspection(options =>
.AddOAuth2Introspection(OAuth2IntrospectionDefaults.AuthenticationScheme, options =>
{
options.Authority = options.Authority;
options.ClientId = options.ClientId;
options.ClientSecret = options.ClientSecret;
options.Authority = authOptions.Authority;
options.IntrospectionEndpoint = authOptions.IntrospectionUrl;
options.ClientId = authOptions.ApiResourceName;
options.ClientSecret = authOptions.ApiResourceSecret;
options.NameClaimType = "sub";
options.DiscoveryPolicy.RequireHttps = authOptions.RequireHttpsMetadata;
options.EnableCaching = true;
options.CacheDuration = TimeSpan.FromMinutes(10);
options.DiscoveryPolicy.ValidateEndpoints = false;
options.EnableCaching = false;
});
if (!string.IsNullOrWhiteSpace(authOptions.RequiredClaimName) && !string.IsNullOrWhiteSpace(authOptions.RequiredClaimNameValue))
services.AddAuthorizationBuilder().AddPolicy("ApiScope", policy =>
policy.RequireClaim(authOptions.RequiredClaimName, authOptions.RequiredClaimNameValue));
else
services.AddAuthorization();
services.AddAuthorization();
return services;
}
+1 -1
View File
@@ -4,7 +4,7 @@ namespace LiteCharms.Features.Hasher;
public sealed partial class HashService(IHashids hasher) : IService
{
[GeneratedRegex(@"\A\b[0-9a-fA-F]+\b\Z")]
[GeneratedRegex(@"\A\b[0-9a-fA-F]+\b\Z", RegexOptions.None, matchTimeoutMilliseconds: 100)]
private static partial Regex HexHashRegex { get; }
[GeneratedRegex(@"\A[0-9a-fA-F]{32}\Z", RegexOptions.None, matchTimeoutMilliseconds: 100)]