Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 95ae2c74cf |
@@ -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.102">
|
<PackageReference Include="Meziantou.Analyzer" Version="3.0.98">
|
||||||
<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.5" />
|
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.3" />
|
||||||
<PackageReference Include="AWSSDK.S3" Version="4.0.24.2" />
|
<PackageReference Include="AWSSDK.S3" Version="4.0.24" />
|
||||||
<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.102">
|
<PackageReference Include="Meziantou.Analyzer" Version="3.0.98">
|
||||||
<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.5" />
|
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.3" />
|
||||||
<PackageReference Include="AWSSDK.S3" Version="4.0.24.2" />
|
<PackageReference Include="AWSSDK.S3" Version="4.0.24" />
|
||||||
<ProjectReference Include="..\LiteCharms.Features\LiteCharms.Features.csproj" />
|
<ProjectReference Include="..\LiteCharms.Features\LiteCharms.Features.csproj" />
|
||||||
|
|
||||||
<!-- global Usings -->
|
<!-- global Usings -->
|
||||||
|
|||||||
@@ -1,128 +0,0 @@
|
|||||||
using LiteCharms.Features.Abstractions;
|
|
||||||
using LiteCharms.Features.MidrandBooks.Orders.Models;
|
|
||||||
using LiteCharms.Features.MidrandBooks.Products.Models;
|
|
||||||
|
|
||||||
namespace LiteCharms.Features.MidrandBooks.Orders;
|
|
||||||
|
|
||||||
public sealed class CartService : IService
|
|
||||||
{
|
|
||||||
private Cart cart = new();
|
|
||||||
|
|
||||||
public Cart GetCart() => cart;
|
|
||||||
|
|
||||||
public void LoadCart(Cart savedCart) => cart = savedCart;
|
|
||||||
|
|
||||||
public void AddItem(ProductPrice productPrice)
|
|
||||||
{
|
|
||||||
var itemExists = false;
|
|
||||||
|
|
||||||
for (var i = 0; i < cart.Items.Count; i++)
|
|
||||||
{
|
|
||||||
if (cart.Items[i].Price!.Id == productPrice.Id)
|
|
||||||
{
|
|
||||||
cart.Items[i].Quantity++;
|
|
||||||
cart.Items[i].Amount += productPrice.Amount;
|
|
||||||
|
|
||||||
itemExists = true;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!itemExists)
|
|
||||||
cart.Items.Add(new CartItem
|
|
||||||
{
|
|
||||||
Price = productPrice,
|
|
||||||
Amount = productPrice.Amount,
|
|
||||||
Quantity = 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
CalculateTotalPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateQuantity(long productPriceId, int newQuantity)
|
|
||||||
{
|
|
||||||
if (newQuantity <= 0)
|
|
||||||
{
|
|
||||||
RemoveAllSameItem(productPriceId);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < cart.Items.Count; i++)
|
|
||||||
{
|
|
||||||
if (cart.Items[i].Price!.Id == productPriceId)
|
|
||||||
{
|
|
||||||
var oldQuantity = cart.Items[i].Quantity;
|
|
||||||
var pricePerUnit = cart.Items[i].Price!.Amount;
|
|
||||||
|
|
||||||
cart.Items[i].Quantity = newQuantity;
|
|
||||||
cart.Items[i].Amount = pricePerUnit * newQuantity;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CalculateTotalPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RemoveOneItem(long productPriceId)
|
|
||||||
{
|
|
||||||
for (var i = 0; i < cart.Items.Count; i++)
|
|
||||||
{
|
|
||||||
if (cart.Items[i].Price!.Id == productPriceId)
|
|
||||||
{
|
|
||||||
if (cart.Items[i].Quantity <= 1)
|
|
||||||
{
|
|
||||||
cart.Items.RemoveAt(i);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cart.Items[i].Quantity--;
|
|
||||||
cart.Items[i].Amount -= cart.Items[i].Price!.Amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CalculateTotalPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RemoveAllSameItem(long productPriceId)
|
|
||||||
{
|
|
||||||
if (cart.Items.Count == 0) return;
|
|
||||||
|
|
||||||
var item = cart.Items.FirstOrDefault(i => i.Price?.Id == productPriceId);
|
|
||||||
|
|
||||||
if (item is not null) cart.Items.Remove(item);
|
|
||||||
|
|
||||||
CalculateTotalPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
if(cart.CustomerId is not null || cart.OrderId is not null)
|
|
||||||
{
|
|
||||||
cart.TotalPrice = 0;
|
|
||||||
cart.TotalVat = 0;
|
|
||||||
cart.Items.Clear();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cart = new Cart();
|
|
||||||
}
|
|
||||||
|
|
||||||
public decimal CalculateTotalPrice()
|
|
||||||
{
|
|
||||||
if (cart.Items.Count == 0) return 0;
|
|
||||||
|
|
||||||
var gross = cart.Items.Sum(i => i.Amount);
|
|
||||||
|
|
||||||
if (!cart.IsVatInclusive) cart.TotalVat = gross * cart.VatRate;
|
|
||||||
|
|
||||||
cart.TotalPrice = gross + cart.TotalVat;
|
|
||||||
|
|
||||||
return cart.TotalPrice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
namespace LiteCharms.Features.MidrandBooks.Orders.Models;
|
|
||||||
|
|
||||||
public sealed class Cart
|
|
||||||
{
|
|
||||||
public long? CustomerId { get; set; }
|
|
||||||
|
|
||||||
public long? OrderId { get; set; }
|
|
||||||
|
|
||||||
public decimal TotalPrice { get; set; }
|
|
||||||
|
|
||||||
public decimal TotalVat { get; set; }
|
|
||||||
|
|
||||||
public decimal VatRate { get; set; } = 0.15m;
|
|
||||||
|
|
||||||
public bool IsVatInclusive { get; set; } = true;
|
|
||||||
|
|
||||||
public IList<CartItem> Items { get; set; } = [];
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using LiteCharms.Features.MidrandBooks.Products.Models;
|
|
||||||
|
|
||||||
namespace LiteCharms.Features.MidrandBooks.Orders.Models;
|
|
||||||
|
|
||||||
public sealed class CartItem
|
|
||||||
{
|
|
||||||
public ProductPrice? Price { get; set; }
|
|
||||||
|
|
||||||
public long Quantity { get; set; }
|
|
||||||
|
|
||||||
public decimal Amount { get; set; }
|
|
||||||
}
|
|
||||||
@@ -136,8 +136,8 @@
|
|||||||
|
|
||||||
<!-- Amazon S3 SDK -->
|
<!-- Amazon S3 SDK -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.5" />
|
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.3" />
|
||||||
<PackageReference Include="AWSSDK.S3" Version="4.0.24.2" />
|
<PackageReference Include="AWSSDK.S3" Version="4.0.24" />
|
||||||
<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}}/connect/token
|
POST {{authority}}
|
||||||
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}}&client_secret={{clientSecret}}&scope={{scope}}
|
grant_type={{grantType}}&client_id={{clientId}}&username={{username}}&password={{password}}&scope={{scope}}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"uat": {
|
|
||||||
"authority": "https://sts.security.khongisa.co.za",
|
|
||||||
"grantType": "client_credentials",
|
|
||||||
"clientId": "midrandbooks-api-scaler-uat",
|
|
||||||
"clientSecret": "secret_0a8dc1f99061590a52b1272db3a1871d2761c79fbd058b2a968911029e4b208a",
|
|
||||||
"scope": "midrandbooks-api"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
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; }
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
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,80 +0,0 @@
|
|||||||
using LiteCharms.Features.Abstractions;
|
|
||||||
|
|
||||||
namespace LiteCharms.Features.Browser;
|
|
||||||
|
|
||||||
public sealed class LocalStorageService(ProtectedLocalStorage storage) : IService
|
|
||||||
{
|
|
||||||
public async ValueTask<Result> DeleteAsync(string key)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await storage.DeleteAsync(key);
|
|
||||||
|
|
||||||
return Result.Ok();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Result> SaveAsync(string key, string value)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await storage.SetAsync(key, value);
|
|
||||||
|
|
||||||
return Result.Ok();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Result> SaveAsync<TValue>(string key, TValue value) where TValue : class
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await storage.SetAsync(key, value);
|
|
||||||
|
|
||||||
return Result.Ok();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Result<string>> GetAsync(string key)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var retrieval = await storage.GetAsync<string>(key);
|
|
||||||
|
|
||||||
return retrieval.Success && !string.IsNullOrWhiteSpace(retrieval.Value)
|
|
||||||
? Result.Ok(retrieval.Value)
|
|
||||||
: Result.Fail($"Could not find object by key {key}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Result<TValue>> GetAsync<TValue>(string key) where TValue : class
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var retrieval = await storage.GetAsync<TValue>(key);
|
|
||||||
|
|
||||||
return retrieval.Success && retrieval.Value is not null
|
|
||||||
? Result.Ok(retrieval.Value)
|
|
||||||
: Result.Fail($"Could not find object by key {key}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
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;
|
||||||
|
|
||||||
@@ -10,14 +9,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 AddLiteCharmsWebSecurity(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddAuthentikUiSecurity(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
var configSection = configuration.GetSection(nameof(AuthentikSettings));
|
||||||
|
|
||||||
var authOptions = new LiteCharmsSettings();
|
var authOptions = new AuthentikSettings();
|
||||||
configSection.Bind(authOptions);
|
configSection.Bind(authOptions);
|
||||||
|
|
||||||
services.Configure<LiteCharmsSettings>(configSection);
|
services.Configure<AuthentikSettings>(configSection);
|
||||||
|
|
||||||
services.AddAuthentication(options =>
|
services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
@@ -28,11 +27,13 @@ public static class Api
|
|||||||
.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.ResponseType = "code";
|
options.SignedOutCallbackPath = "/signout-callback-oidc";
|
||||||
|
|
||||||
|
options.ResponseType = "code";
|
||||||
options.SaveTokens = true;
|
options.SaveTokens = true;
|
||||||
options.GetClaimsFromUserInfoEndpoint = true;
|
options.GetClaimsFromUserInfoEndpoint = true;
|
||||||
|
|
||||||
@@ -43,16 +44,17 @@ public static class Api
|
|||||||
|
|
||||||
options.Events = new OpenIdConnectEvents
|
options.Events = new OpenIdConnectEvents
|
||||||
{
|
{
|
||||||
OnRedirectToIdentityProviderForSignOut = context =>
|
OnRedirectToIdentityProvider = context =>
|
||||||
{
|
{
|
||||||
var idToken = context.ProtocolMessage.IdTokenHint;
|
if (!string.IsNullOrEmpty(context.ProtocolMessage.RedirectUri) && context.ProtocolMessage.RedirectUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(idToken))
|
|
||||||
{
|
{
|
||||||
var tokens = context.Properties.GetTokens();
|
var uriBuilder = new UriBuilder(context.ProtocolMessage.RedirectUri)
|
||||||
var idTokenItem = tokens.FirstOrDefault(t => string.Equals(t.Name, "id_token", StringComparison.Ordinal));
|
{
|
||||||
|
Scheme = "https",
|
||||||
|
Port = -1,
|
||||||
|
};
|
||||||
|
|
||||||
if (idTokenItem != null) context.ProtocolMessage.IdTokenHint = idTokenItem.Value;
|
context.ProtocolMessage.RedirectUri = uriBuilder.Uri.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
@@ -60,34 +62,40 @@ public static class Api
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddCascadingAuthenticationState();
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddLiteCharmsApiSecurity(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddAuthentikApiSecurity(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
var configSection = configuration.GetSection(nameof(AuthentikSettings));
|
||||||
|
|
||||||
var authOptions = new LiteCharmsSettings();
|
var authOptions = new AuthentikSettings();
|
||||||
configSection.Bind(authOptions);
|
configSection.Bind(authOptions);
|
||||||
|
|
||||||
services.Configure<LiteCharmsSettings>(configSection);
|
services.Configure<AuthentikSettings>(configSection);
|
||||||
|
|
||||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
services.AddAuthentication(OAuth2IntrospectionDefaults.AuthenticationScheme)
|
||||||
.AddJwtBearer(options =>
|
.AddOAuth2Introspection(OAuth2IntrospectionDefaults.AuthenticationScheme, options =>
|
||||||
{
|
{
|
||||||
options.Authority = authOptions.Authority;
|
options.Authority = authOptions.Authority;
|
||||||
options.Audience = authOptions.Audience;
|
options.IntrospectionEndpoint = authOptions.IntrospectionEndpoint;
|
||||||
options.TokenValidationParameters = new TokenValidationParameters
|
options.ClientId = authOptions.ClientId;
|
||||||
{
|
options.ClientSecret = authOptions.ClientSecret;
|
||||||
ValidIssuer = authOptions.Authority,
|
|
||||||
ValidateAudience = true,
|
options.NameClaimType = "sub";
|
||||||
ValidateIssuer = true,
|
options.DiscoveryPolicy.RequireHttps = authOptions.RequireHttpsMetadata;
|
||||||
};
|
options.DiscoveryPolicy.ValidateEndpoints = false;
|
||||||
|
options.EnableCaching = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddAuthorization();
|
if (!string.IsNullOrWhiteSpace(authOptions.RequiredClaimName) && !string.IsNullOrWhiteSpace(authOptions.RequiredClaimNameValue))
|
||||||
|
{
|
||||||
|
services.AddAuthorizationBuilder()
|
||||||
|
.AddPolicy("RequiredScope", policy =>
|
||||||
|
policy.RequireClaim(authOptions.RequiredClaimName, authOptions.RequiredClaimNameValue));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
services.AddAuthorization();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
@@ -98,21 +106,20 @@ public static class Api
|
|||||||
{
|
{
|
||||||
await context.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties
|
await context.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties
|
||||||
{
|
{
|
||||||
RedirectUri = redirectUri,
|
RedirectUri = redirectUri,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapGet("/logout", async (HttpContext context) =>
|
app.MapGet("/logout", async (HttpContext context, IHttpClientFactory httpClientFactory, IOptions<AuthentikSettings> settings) =>
|
||||||
{
|
{
|
||||||
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);
|
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
|
||||||
|
string currentBaseUrl = $"https://{context.Request.Host}{context.Request.PathBase}/";
|
||||||
|
|
||||||
|
await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties
|
||||||
|
{
|
||||||
|
RedirectUri = currentBaseUrl
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
|||||||
@@ -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.102">
|
<PackageReference Include="Meziantou.Analyzer" Version="3.0.98">
|
||||||
<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.5" />
|
<PackageReference Include="AWSSDK.Extensions.NetCore.Setup" Version="4.0.4.3" />
|
||||||
<PackageReference Include="AWSSDK.S3" Version="4.0.24.2" />
|
<PackageReference Include="AWSSDK.S3" Version="4.0.24" />
|
||||||
|
|
||||||
<!-- global Usings -->
|
<!-- global Usings -->
|
||||||
<Using Include="Amazon.S3" />
|
<Using Include="Amazon.S3" />
|
||||||
@@ -182,7 +182,6 @@
|
|||||||
|
|
||||||
<!-- Shared Usings -->
|
<!-- Shared Usings -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Using Include="Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage" />
|
|
||||||
<Using Include="System.Reflection" />
|
<Using Include="System.Reflection" />
|
||||||
<Using Include="Microsoft.Extensions.DependencyInjection.Extensions" />
|
<Using Include="Microsoft.Extensions.DependencyInjection.Extensions" />
|
||||||
<Using Include="Microsoft.AspNetCore.Routing" />
|
<Using Include="Microsoft.AspNetCore.Routing" />
|
||||||
|
|||||||
Reference in New Issue
Block a user