Compare commits

..

3 Commits

Author SHA1 Message Date
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
3 changed files with 20 additions and 8 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
@@ -0,0 +1,6 @@
## Authentik Token Request
POST {{authority}}
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: identity
grant_type={{grantType}}&client_id={{clientId}}&client_secret={{clientSecret}}&username={{username}}&password={{password}}&scope={{scope}}
+13 -8
View File
@@ -11,26 +11,31 @@ 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.ClientId = authOptions.ApiResourceName;
options.ClientSecret = authOptions.ApiResourceSecret;
options.DiscoveryPolicy.RequireHttps = authOptions.RequireHttpsMetadata;
options.EnableCaching = true;
options.CacheDuration = TimeSpan.FromMinutes(10);
});
if (!string.IsNullOrWhiteSpace(authOptions.RequiredClaimName) && !string.IsNullOrWhiteSpace(authOptions.RequiredClaimNameValue))
services.AddAuthorizationBuilder().AddPolicy("ApiScope", policy =>
{
services.AddAuthorizationBuilder()
.AddPolicy("ApiScope", policy =>
policy.RequireClaim(authOptions.RequiredClaimName, authOptions.RequiredClaimNameValue));
}
else
services.AddAuthorization();