Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c4d3bb4cdf | |||
| 65f102f18a | |||
| cdc80db214 | |||
| 4576b5aa2b | |||
| 3847927ace | |||
| d38d1dd059 | |||
| c27aba1954 | |||
| e646d16053 |
@@ -41,6 +41,19 @@ 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 =>
|
||||||
|
{
|
||||||
|
var fallbackUri = context.ProtocolMessage.RedirectUri;
|
||||||
|
|
||||||
|
if (fallbackUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
|
||||||
|
context.ProtocolMessage.RedirectUri = fallbackUri.Replace("http://", "https://", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
@@ -87,36 +100,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, IHttpClientFactory httpClientFactory, IOptions<AuthentikSettings> settings) =>
|
app.MapGet("/logout", async (HttpContext context, IHttpClientFactory httpClientFactory, IOptions<AuthentikSettings> settings) =>
|
||||||
{
|
{
|
||||||
var authOptions = settings.Value;
|
|
||||||
var accessToken = await context.GetTokenAsync("access_token");
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(accessToken))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var client = httpClientFactory.CreateClient();
|
|
||||||
|
|
||||||
var requestContent = new FormUrlEncodedContent(new Dictionary<string, string>(StringComparer.Ordinal)
|
|
||||||
{
|
|
||||||
{ "token", accessToken },
|
|
||||||
{ "client_id", authOptions.ClientId! },
|
|
||||||
{ "client_secret", authOptions.ClientSecret! },
|
|
||||||
});
|
|
||||||
|
|
||||||
await client.PostAsync(authOptions.RevokationEndpoint, requestContent, context.RequestAborted);
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
}
|
|
||||||
|
|
||||||
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
|
||||||
return Results.Redirect("/");
|
string currentBaseUrl = $"https://{context.Request.Host}{context.Request.PathBase}/";
|
||||||
|
|
||||||
|
await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties
|
||||||
|
{
|
||||||
|
RedirectUri = currentBaseUrl
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
|||||||
Reference in New Issue
Block a user