Merge pull request 'payments' (#69) from payments into master
Reviewed-on: #69
This commit was merged in pull request #69.
This commit is contained in:
@@ -363,3 +363,4 @@ MigrationBackup/
|
|||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
/LiteCharms.Features.Tests/http/http-client.env.json
|
/LiteCharms.Features.Tests/http/http-client.env.json
|
||||||
/LiteCharms.Features.Tests/http/midrandshop-api/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}}
|
||||||
@@ -11,26 +11,31 @@ public static class Api
|
|||||||
|
|
||||||
public static IServiceCollection AddAuthentic(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddAuthentic(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
|
var configSection = configuration.GetSection(nameof(AuthentikSettings));
|
||||||
|
|
||||||
var authOptions = new AuthentikSettings();
|
var authOptions = new AuthentikSettings();
|
||||||
|
configSection.Bind(authOptions);
|
||||||
|
|
||||||
configuration.GetSection("Authentik").Bind(authOptions);
|
services.Configure<AuthentikSettings>(configSection);
|
||||||
|
|
||||||
services.Configure<AuthentikSettings>(configuration.GetSection(nameof(AuthentikSettings)));
|
|
||||||
|
|
||||||
services.AddAuthentication(OAuth2IntrospectionDefaults.AuthenticationScheme)
|
services.AddAuthentication(OAuth2IntrospectionDefaults.AuthenticationScheme)
|
||||||
.AddOAuth2Introspection(options =>
|
.AddOAuth2Introspection(OAuth2IntrospectionDefaults.AuthenticationScheme, options =>
|
||||||
{
|
{
|
||||||
options.Authority = options.Authority;
|
options.Authority = authOptions.Authority;
|
||||||
options.ClientId = options.ClientId;
|
options.ClientId = authOptions.ApiResourceName;
|
||||||
options.ClientSecret = options.ClientSecret;
|
options.ClientSecret = authOptions.ApiResourceSecret;
|
||||||
|
|
||||||
options.DiscoveryPolicy.RequireHttps = authOptions.RequireHttpsMetadata;
|
options.DiscoveryPolicy.RequireHttps = authOptions.RequireHttpsMetadata;
|
||||||
options.EnableCaching = true;
|
options.EnableCaching = true;
|
||||||
options.CacheDuration = TimeSpan.FromMinutes(10);
|
options.CacheDuration = TimeSpan.FromMinutes(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(authOptions.RequiredClaimName) && !string.IsNullOrWhiteSpace(authOptions.RequiredClaimNameValue))
|
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));
|
policy.RequireClaim(authOptions.RequiredClaimName, authOptions.RequiredClaimNameValue));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
services.AddAuthorization();
|
services.AddAuthorization();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user