Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5140da2c6c | |||
| 02ff14ccc8 | |||
| 0ad410c64e | |||
| e193aa7c1c | |||
| 840d4568e2 | |||
| 6e580ecdf6 | |||
| 60095057b7 | |||
| 4c194c1141 | |||
| b41136e2c7 | |||
| 41eb4daeb4 | |||
| c423f04b42 | |||
| 7fe5f7aef3 | |||
| a567fc7cd7 | |||
| 31254932ae | |||
| c53434a578 | |||
| 5a0aae8182 | |||
| 3f3e0dbe88 | |||
| 8d8ebffabf | |||
| dc4addb43a | |||
| e2d29261da | |||
| 5d5b59d610 | |||
| f001b02633 | |||
| 90a11dc65e | |||
| de955a96a8 | |||
| cdf5cfb5cd | |||
| c4d3bb4cdf | |||
| 65f102f18a | |||
| cdc80db214 | |||
| 4576b5aa2b | |||
| 3847927ace | |||
| d38d1dd059 | |||
| c27aba1954 | |||
| e646d16053 | |||
| 1c946dab26 | |||
| 20c3ad9569 | |||
| 9977cf27b9 | |||
| cf7eed0603 | |||
| 8e9ac1e1ad | |||
| fa79bd8021 |
@@ -11,7 +11,7 @@
|
|||||||
<!-- Quartz Scheduler-->
|
<!-- Quartz Scheduler-->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||||
<PackageReference Include="Meziantou.Analyzer" Version="3.0.98">
|
<PackageReference Include="Meziantou.Analyzer" Version="3.0.101">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@@ -116,8 +116,8 @@
|
|||||||
|
|
||||||
<!-- Amazon S3 SDK -->
|
<!-- Amazon S3 SDK -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.3" />
|
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.4" />
|
||||||
<PackageReference Include="AWSSDK.S3" Version="4.0.24" />
|
<PackageReference Include="AWSSDK.S3" Version="4.0.24.1" />
|
||||||
<ProjectReference Include="..\LiteCharms.Features\LiteCharms.Features.csproj" />
|
<ProjectReference Include="..\LiteCharms.Features\LiteCharms.Features.csproj" />
|
||||||
|
|
||||||
<!-- global Usings -->
|
<!-- global Usings -->
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
<!-- Quartz Scheduler-->
|
<!-- Quartz Scheduler-->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Humanizer" Version="3.0.10" />
|
<PackageReference Include="Humanizer" Version="3.0.10" />
|
||||||
<PackageReference Include="Meziantou.Analyzer" Version="3.0.98">
|
<PackageReference Include="Meziantou.Analyzer" Version="3.0.101">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@@ -136,8 +136,8 @@
|
|||||||
|
|
||||||
<!-- Amazon S3 SDK -->
|
<!-- Amazon S3 SDK -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.3" />
|
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.4" />
|
||||||
<PackageReference Include="AWSSDK.S3" Version="4.0.24" />
|
<PackageReference Include="AWSSDK.S3" Version="4.0.24.1" />
|
||||||
<ProjectReference Include="..\LiteCharms.Features\LiteCharms.Features.csproj" />
|
<ProjectReference Include="..\LiteCharms.Features\LiteCharms.Features.csproj" />
|
||||||
|
|
||||||
<!-- global Usings -->
|
<!-- global Usings -->
|
||||||
|
|||||||
@@ -136,8 +136,8 @@
|
|||||||
|
|
||||||
<!-- Amazon S3 SDK -->
|
<!-- Amazon S3 SDK -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.3" />
|
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.4" />
|
||||||
<PackageReference Include="AWSSDK.S3" Version="4.0.24" />
|
<PackageReference Include="AWSSDK.S3" Version="4.0.24.1" />
|
||||||
<ProjectReference Include="..\LiteCharms.Features\LiteCharms.Features.csproj" />
|
<ProjectReference Include="..\LiteCharms.Features\LiteCharms.Features.csproj" />
|
||||||
|
|
||||||
<!-- global Usings -->
|
<!-- global Usings -->
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
### Authentik Token Request (Service Account Explicit)
|
### Authentik Token Request (Service Account Explicit)
|
||||||
POST {{authority}}
|
POST {{authority}}/connect/token
|
||||||
Content-Type: application/x-www-form-urlencoded
|
Content-Type: application/x-www-form-urlencoded
|
||||||
Accept-Encoding: identity
|
Accept-Encoding: identity
|
||||||
|
|
||||||
grant_type={{grantType}}&client_id={{clientId}}&username={{username}}&password={{password}}&scope={{scope}}
|
grant_type={{grantType}}&client_id={{clientId}}&client_secret={{clientSecret}}&scope={{scope}}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"uat": {
|
||||||
|
"authority": "https://sts.security.khongisa.co.za",
|
||||||
|
"grantType": "client_credentials",
|
||||||
|
"clientId": "midrandbooks-api-scaler-uat",
|
||||||
|
"clientSecret": "secret_0a8dc1f99061590a52b1272db3a1871d2761c79fbd058b2a968911029e4b208a",
|
||||||
|
"scope": "midrandbooks-api"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
namespace LiteCharms.Features.Api.Configuration;
|
|
||||||
|
|
||||||
public sealed class AuthentikSettings
|
|
||||||
{
|
|
||||||
public string? Authority { get; set; }
|
|
||||||
|
|
||||||
public string? IntrospectionUrl { get; set; }
|
|
||||||
|
|
||||||
public string? ClientId { get; set; }
|
|
||||||
|
|
||||||
public string? ClientSecret { get; set; }
|
|
||||||
|
|
||||||
public string? RequiredClaimName { get; set; }
|
|
||||||
|
|
||||||
public string? RequiredClaimNameValue { get; set; }
|
|
||||||
|
|
||||||
public bool RequireHttpsMetadata { get; set; }
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace LiteCharms.Features.Api.Configuration;
|
||||||
|
|
||||||
|
public sealed class LiteCharmsSettings
|
||||||
|
{
|
||||||
|
public string? Authority { get; set; }
|
||||||
|
|
||||||
|
public string? ClientId { get; set; }
|
||||||
|
|
||||||
|
public string? ClientSecret { get; set; }
|
||||||
|
|
||||||
|
public string? Audience { get; set; }
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using LiteCharms.Features.Abstractions;
|
using LiteCharms.Features.Abstractions;
|
||||||
using LiteCharms.Features.Api;
|
using LiteCharms.Features.Api;
|
||||||
using LiteCharms.Features.Api.Configuration;
|
using LiteCharms.Features.Api.Configuration;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
|
||||||
namespace LiteCharms.Features.Extensions;
|
namespace LiteCharms.Features.Extensions;
|
||||||
|
|
||||||
@@ -9,14 +10,14 @@ public static class Api
|
|||||||
public const string Books = nameof(Books);
|
public const string Books = nameof(Books);
|
||||||
public const string Payments = nameof(Payments);
|
public const string Payments = nameof(Payments);
|
||||||
|
|
||||||
public static IServiceCollection AddAuthentikUiSecurity(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddLiteCharmsWebSecurity(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var configSection = configuration.GetSection(nameof(AuthentikSettings));
|
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
||||||
|
|
||||||
var authOptions = new AuthentikSettings();
|
var authOptions = new LiteCharmsSettings();
|
||||||
configSection.Bind(authOptions);
|
configSection.Bind(authOptions);
|
||||||
|
|
||||||
services.Configure<AuthentikSettings>(configSection);
|
services.Configure<LiteCharmsSettings>(configSection);
|
||||||
|
|
||||||
services.AddAuthentication(options =>
|
services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
@@ -30,8 +31,8 @@ public static class Api
|
|||||||
|
|
||||||
options.ClientId = authOptions.ClientId;
|
options.ClientId = authOptions.ClientId;
|
||||||
options.ClientSecret = authOptions.ClientSecret;
|
options.ClientSecret = authOptions.ClientSecret;
|
||||||
|
|
||||||
options.ResponseType = "code";
|
options.ResponseType = "code";
|
||||||
|
|
||||||
options.SaveTokens = true;
|
options.SaveTokens = true;
|
||||||
options.GetClaimsFromUserInfoEndpoint = true;
|
options.GetClaimsFromUserInfoEndpoint = true;
|
||||||
|
|
||||||
@@ -39,46 +40,84 @@ public static class Api
|
|||||||
options.Scope.Add("openid");
|
options.Scope.Add("openid");
|
||||||
options.Scope.Add("profile");
|
options.Scope.Add("profile");
|
||||||
options.Scope.Add("email");
|
options.Scope.Add("email");
|
||||||
|
|
||||||
|
options.Events = new OpenIdConnectEvents
|
||||||
|
{
|
||||||
|
OnRedirectToIdentityProviderForSignOut = context =>
|
||||||
|
{
|
||||||
|
var idToken = context.ProtocolMessage.IdTokenHint;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(idToken))
|
||||||
|
{
|
||||||
|
var tokens = context.Properties.GetTokens();
|
||||||
|
var idTokenItem = tokens.FirstOrDefault(t => string.Equals(t.Name, "id_token", StringComparison.Ordinal));
|
||||||
|
|
||||||
|
if (idTokenItem != null) context.ProtocolMessage.IdTokenHint = idTokenItem.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
services.AddCascadingAuthenticationState();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddAuthentikApiSecurity(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddLiteCharmsApiSecurity(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var configSection = configuration.GetSection(nameof(AuthentikSettings));
|
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
||||||
|
|
||||||
var authOptions = new AuthentikSettings();
|
var authOptions = new LiteCharmsSettings();
|
||||||
configSection.Bind(authOptions);
|
configSection.Bind(authOptions);
|
||||||
|
|
||||||
services.Configure<AuthentikSettings>(configSection);
|
services.Configure<LiteCharmsSettings>(configSection);
|
||||||
|
|
||||||
services.AddAuthentication(OAuth2IntrospectionDefaults.AuthenticationScheme)
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
.AddOAuth2Introspection(OAuth2IntrospectionDefaults.AuthenticationScheme, options =>
|
.AddJwtBearer(options =>
|
||||||
{
|
{
|
||||||
options.Authority = authOptions.Authority;
|
options.Authority = authOptions.Authority;
|
||||||
options.IntrospectionEndpoint = authOptions.IntrospectionUrl;
|
options.Audience = authOptions.Audience;
|
||||||
options.ClientId = authOptions.ClientId;
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
options.ClientSecret = authOptions.ClientSecret;
|
{
|
||||||
|
ValidIssuer = authOptions.Authority,
|
||||||
options.NameClaimType = "sub";
|
ValidateAudience = true,
|
||||||
options.DiscoveryPolicy.RequireHttps = authOptions.RequireHttpsMetadata;
|
ValidateIssuer = true,
|
||||||
options.DiscoveryPolicy.ValidateEndpoints = false;
|
};
|
||||||
options.EnableCaching = false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(authOptions.RequiredClaimName) && !string.IsNullOrWhiteSpace(authOptions.RequiredClaimNameValue))
|
services.AddAuthorization();
|
||||||
{
|
|
||||||
services.AddAuthorizationBuilder()
|
|
||||||
.AddPolicy("RequiredScope", policy =>
|
|
||||||
policy.RequireClaim(authOptions.RequiredClaimName, authOptions.RequiredClaimNameValue));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
services.AddAuthorization();
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WebApplication AddSecurityEndpoints(this WebApplication app)
|
||||||
|
{
|
||||||
|
app.MapGet("/login", async (HttpContext context, string redirectUri = "/") =>
|
||||||
|
{
|
||||||
|
await context.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties
|
||||||
|
{
|
||||||
|
RedirectUri = redirectUri,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.MapGet("/logout", async (HttpContext context) =>
|
||||||
|
{
|
||||||
|
var idToken = await context.GetTokenAsync("id_token");
|
||||||
|
|
||||||
|
var authProperties = new AuthenticationProperties { RedirectUri = "/", };
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(idToken))
|
||||||
|
authProperties.Parameters.Add("id_token_hint", idToken);
|
||||||
|
|
||||||
|
await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, authProperties);
|
||||||
|
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
});
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddApiServices(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddApiServices(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
services.AddHttpClient();
|
services.AddHttpClient();
|
||||||
|
|||||||
@@ -38,9 +38,10 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Certificate" Version="10.0.8" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.Certificate" Version="10.0.8" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.8" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.8" />
|
||||||
|
|
||||||
<Using Include="Microsoft.AspNetCore.Authentication.OpenIdConnect"/>
|
<Using Include="Microsoft.AspNetCore.Authentication" />
|
||||||
<Using Include="Microsoft.AspNetCore.Authentication.Cookies"/>
|
<Using Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
|
||||||
<Using Include="IdentityModel.AspNetCore.OAuth2Introspection"/>
|
<Using Include="Microsoft.AspNetCore.Authentication.Cookies" />
|
||||||
|
<Using Include="IdentityModel.AspNetCore.OAuth2Introspection" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- API Versioning -->
|
<!-- API Versioning -->
|
||||||
@@ -66,7 +67,7 @@
|
|||||||
<!-- Quartz Scheduler-->
|
<!-- Quartz Scheduler-->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Hashids.net" Version="1.7.0" />
|
<PackageReference Include="Hashids.net" Version="1.7.0" />
|
||||||
<PackageReference Include="Meziantou.Analyzer" Version="3.0.98">
|
<PackageReference Include="Meziantou.Analyzer" Version="3.0.101">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@@ -170,8 +171,8 @@
|
|||||||
|
|
||||||
<!-- Amazon S3 SDK -->
|
<!-- Amazon S3 SDK -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.3" />
|
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.4" />
|
||||||
<PackageReference Include="AWSSDK.S3" Version="4.0.24" />
|
<PackageReference Include="AWSSDK.S3" Version="4.0.24.1" />
|
||||||
|
|
||||||
<!-- global Usings -->
|
<!-- global Usings -->
|
||||||
<Using Include="Amazon.S3" />
|
<Using Include="Amazon.S3" />
|
||||||
|
|||||||
Reference in New Issue
Block a user