Compare commits

..

10 Commits

Author SHA1 Message Date
khwezi c4d3bb4cdf Merge pull request 'Simplified login process' (#80) from payments into master
Reviewed-on: #80
2026-06-05 08:18:12 +02:00
Khwezi Mngoma 65f102f18a Simplified login process
continuous-integration/drone/pr Build is passing
2026-06-05 08:17:32 +02:00
khwezi cdc80db214 Merge pull request 'Refactored logout endpoint' (#79) from payments into master
Reviewed-on: #79
2026-06-05 08:15:50 +02:00
Khwezi Mngoma 4576b5aa2b Refactored logout endpoint
continuous-integration/drone/pr Build is passing
2026-06-05 08:15:13 +02:00
khwezi 3847927ace Merge pull request 'Added port stripping' (#78) from payments into master
Reviewed-on: #78
2026-06-05 07:37:16 +02:00
Khwezi Mngoma d38d1dd059 Added port stripping
continuous-integration/drone/pr Build is passing
2026-06-05 07:36:41 +02:00
khwezi c27aba1954 Merge pull request 'Forcing login https proto on redirect' (#77) from payments into master
Reviewed-on: #77
2026-06-05 06:40:33 +02:00
Khwezi Mngoma e646d16053 Forcing login https proto on redirect
continuous-integration/drone/pr Build is passing
2026-06-05 06:39:47 +02:00
khwezi 1c946dab26 Merge pull request 'Refactored security components' (#76) from payments into master
Reviewed-on: #76
2026-06-05 05:44:47 +02:00
Khwezi Mngoma 20c3ad9569 Refactored security components
continuous-integration/drone/pr Build is passing
2026-06-05 05:43:56 +02:00
3 changed files with 39 additions and 6 deletions
@@ -4,7 +4,11 @@ public sealed class AuthentikSettings
{
public string? Authority { get; set; }
public string? IntrospectionUrl { get; set; }
public string? IntrospectionEndpoint { get; set; }
public string? MetadataEndpoint { get; set; }
public string? RevokationEndpoint { get; set; }
public string? ClientId { get; set; }
+33 -5
View File
@@ -27,11 +27,11 @@ public static class Api
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.Authority = authOptions.Authority;
options.MetadataAddress = authOptions.MetadataEndpoint;
options.ClientId = authOptions.ClientId;
options.ClientSecret = authOptions.ClientSecret;
options.SignedOutCallbackPath = "/signout-callback-oidc";
options.SignedOutRedirectUri = "/";
options.ResponseType = "code";
options.SaveTokens = true;
@@ -44,12 +44,15 @@ public static class Api
options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProviderForSignOut = context =>
OnRedirectToIdentityProvider = context =>
{
context.ProtocolMessage.PostLogoutRedirectUri = context.Properties.RedirectUri;
var fallbackUri = context.ProtocolMessage.RedirectUri;
if (fallbackUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
context.ProtocolMessage.RedirectUri = fallbackUri.Replace("http://", "https://", StringComparison.OrdinalIgnoreCase);
return Task.CompletedTask;
},
}
};
});
@@ -69,7 +72,7 @@ public static class Api
.AddOAuth2Introspection(OAuth2IntrospectionDefaults.AuthenticationScheme, options =>
{
options.Authority = authOptions.Authority;
options.IntrospectionEndpoint = authOptions.IntrospectionUrl;
options.IntrospectionEndpoint = authOptions.IntrospectionEndpoint;
options.ClientId = authOptions.ClientId;
options.ClientSecret = authOptions.ClientSecret;
@@ -91,6 +94,31 @@ public static class Api
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, IHttpClientFactory httpClientFactory, IOptions<AuthentikSettings> settings) =>
{
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;
}
public static IServiceCollection AddApiServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddHttpClient();
@@ -38,6 +38,7 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.Certificate" Version="10.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.8" />
<Using Include="Microsoft.AspNetCore.Authentication"/>
<Using Include="Microsoft.AspNetCore.Authentication.OpenIdConnect"/>
<Using Include="Microsoft.AspNetCore.Authentication.Cookies"/>
<Using Include="IdentityModel.AspNetCore.OAuth2Introspection"/>