Compare commits
95 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fe5f7aef3 | |||
| a567fc7cd7 | |||
| 31254932ae | |||
| c53434a578 | |||
| 5a0aae8182 | |||
| 3f3e0dbe88 | |||
| 8d8ebffabf | |||
| dc4addb43a | |||
| e2d29261da | |||
| 5d5b59d610 | |||
| f001b02633 | |||
| 90a11dc65e | |||
| de955a96a8 | |||
| cdf5cfb5cd | |||
| c4d3bb4cdf | |||
| 65f102f18a | |||
| cdc80db214 | |||
| 3847927ace | |||
| c27aba1954 | |||
| 1c946dab26 | |||
| 9977cf27b9 | |||
| 8e9ac1e1ad | |||
| 16dae7c9fb | |||
| f8153e86b4 | |||
| 84d33d3607 | |||
| f51cc03327 | |||
| aff6fcabf4 | |||
| 8140b5fe65 | |||
| 9285cedfa9 | |||
| 343874551a | |||
| 0eac9d533f | |||
| 24ba609e0c | |||
| 29f6d66c44 | |||
| bcfc9ef962 | |||
| b4e967acc9 | |||
| 205bbb9f3f | |||
| 73ef4b04a9 | |||
| 780415b6d4 | |||
| 879094073a | |||
| b369dad452 | |||
| c938bfec09 | |||
| adc14038db | |||
| 61cb6c2228 | |||
| e7a798b5e9 | |||
| 41b6b71b31 | |||
| ee6beef603 | |||
| 1c3f3eaf0d | |||
| 2e77666d9e | |||
| 1977b6b301 | |||
| 0ab14d8b63 | |||
| 466458e230 | |||
| 141d32f591 | |||
| d9e7f225ae | |||
| 6ae63e2ad1 | |||
| f5efdde37c | |||
| 1592d5dc8f | |||
| 50a8a59d92 | |||
| b70d9559b0 | |||
| 81d5e8f07c | |||
| 20a53942b5 | |||
| 9edb2aa4aa | |||
| 6ed023f2cf | |||
| 2c9f5a846c | |||
| 41f7c05be3 | |||
| 1a03355e84 | |||
| 7743c3178e | |||
| ab3d8e6e9a | |||
| db4c348288 | |||
| 6683234642 | |||
| 6ddbb9479a | |||
| 6c7349a0f8 | |||
| e97fd6cd3f | |||
| 184c7c252a | |||
| bfe8c458d6 | |||
| e6e0475db1 | |||
| 5090c60797 | |||
| 9432252e15 | |||
| 47111a1a3a | |||
| 6eb3d50375 | |||
| 4deb732804 | |||
| 20d9387d0b | |||
| 9f6d0ccaa0 | |||
| 1acbc4d213 | |||
| 8c99668fac | |||
| ad44f46204 | |||
| 49d999c1e3 | |||
| 9ed4777a18 | |||
| 0cf44f68cc | |||
| 41ed5a4288 | |||
| bbcba5e06c | |||
| 502cc326dd | |||
| 4675d4c5fc | |||
| f80bb2fff9 | |||
| 6767906b0d | |||
| a344af4498 |
@@ -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,22 +0,0 @@
|
|||||||
namespace LiteCharms.Features.Api.Configuration;
|
|
||||||
|
|
||||||
public sealed class AuthentikSettings
|
|
||||||
{
|
|
||||||
public string? Authority { get; set; }
|
|
||||||
|
|
||||||
public string? IntrospectionEndpoint { get; set; }
|
|
||||||
|
|
||||||
public string? MetadataEndpoint { get; set; }
|
|
||||||
|
|
||||||
public string? RevokationEndpoint { 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 AddLiteCharmsUiSecurity(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 =>
|
||||||
{
|
{
|
||||||
@@ -26,14 +27,12 @@ public static class Api
|
|||||||
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
|
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
|
||||||
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
|
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
|
||||||
{
|
{
|
||||||
options.Authority = authOptions.Authority;
|
options.Authority = authOptions.Authority;
|
||||||
options.MetadataAddress = authOptions.MetadataEndpoint;
|
|
||||||
|
|
||||||
options.ClientId = authOptions.ClientId;
|
options.ClientId = authOptions.ClientId;
|
||||||
options.ClientSecret = authOptions.ClientSecret;
|
options.ClientSecret = authOptions.ClientSecret;
|
||||||
options.SignedOutCallbackPath = "/signout-callback-oidc";
|
|
||||||
|
|
||||||
options.ResponseType = "code";
|
options.ResponseType = "code";
|
||||||
|
|
||||||
options.SaveTokens = true;
|
options.SaveTokens = true;
|
||||||
options.GetClaimsFromUserInfoEndpoint = true;
|
options.GetClaimsFromUserInfoEndpoint = true;
|
||||||
|
|
||||||
@@ -41,61 +40,36 @@ 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
|
|
||||||
{
|
|
||||||
OnRedirectToIdentityProvider = context =>
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(context.ProtocolMessage.RedirectUri) && context.ProtocolMessage.RedirectUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
var uriBuilder = new UriBuilder(context.ProtocolMessage.RedirectUri)
|
|
||||||
{
|
|
||||||
Scheme = "https",
|
|
||||||
Port = -1,
|
|
||||||
};
|
|
||||||
|
|
||||||
context.ProtocolMessage.RedirectUri = uriBuilder.Uri.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
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.IntrospectionEndpoint;
|
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;
|
||||||
}
|
}
|
||||||
@@ -110,7 +84,7 @@ public static class Api
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapGet("/logout", async (HttpContext context, IHttpClientFactory httpClientFactory, IOptions<AuthentikSettings> settings) =>
|
app.MapGet("/logout", async (HttpContext context, IHttpClientFactory httpClientFactory, IOptions<LiteCharmsSettings> settings) =>
|
||||||
{
|
{
|
||||||
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
|
||||||
|
|||||||
@@ -38,10 +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"/>
|
<Using Include="Microsoft.AspNetCore.Authentication" />
|
||||||
<Using Include="Microsoft.AspNetCore.Authentication.OpenIdConnect"/>
|
<Using Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
|
||||||
<Using Include="Microsoft.AspNetCore.Authentication.Cookies"/>
|
<Using Include="Microsoft.AspNetCore.Authentication.Cookies" />
|
||||||
<Using Include="IdentityModel.AspNetCore.OAuth2Introspection"/>
|
<Using Include="IdentityModel.AspNetCore.OAuth2Introspection" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- API Versioning -->
|
<!-- API Versioning -->
|
||||||
@@ -67,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>
|
||||||
@@ -171,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