Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 029f5b5d8a | |||
| ff81325020 | |||
| 3e1b2eb48c | |||
| fc884c2350 |
+9
-14
@@ -67,21 +67,14 @@ builder.Services.AddAuthentication(options =>
|
|||||||
|
|
||||||
options.Events = new OpenIdConnectEvents
|
options.Events = new OpenIdConnectEvents
|
||||||
{
|
{
|
||||||
OnRedirectToIdentityProviderForSignOut = async callbackContext =>
|
OnRedirectToIdentityProvider = context =>
|
||||||
{
|
{
|
||||||
var request = callbackContext.Request;
|
var fallbackUri = context.ProtocolMessage.RedirectUri;
|
||||||
string currentBaseUrl = $"{request.Scheme}://{request.Host}{request.PathBase}/";
|
|
||||||
|
|
||||||
callbackContext.ProtocolMessage.PostLogoutRedirectUri = currentBaseUrl;
|
if (fallbackUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
|
||||||
|
context.ProtocolMessage.RedirectUri = fallbackUri.Replace("http://", "https://", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
var idToken = await callbackContext.HttpContext.GetTokenAsync("id_token");
|
return Task.CompletedTask;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(idToken)) callbackContext.ProtocolMessage.IdTokenHint = idToken;
|
|
||||||
|
|
||||||
if (callbackContext.ProtocolMessage.RedirectUri.StartsWith("http://"))
|
|
||||||
{
|
|
||||||
callbackContext.ProtocolMessage.RedirectUri = callbackContext.ProtocolMessage.RedirectUri.Replace("http://", "https://");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -100,6 +93,8 @@ var scheduler = await schedulerFactory.GetScheduler(ShopSchedulerName);
|
|||||||
if (!scheduler!.IsStarted)
|
if (!scheduler!.IsStarted)
|
||||||
await scheduler.Start();
|
await scheduler.Start();
|
||||||
|
|
||||||
|
app.UseForwardedHeaders();
|
||||||
|
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
||||||
@@ -115,7 +110,6 @@ app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages:
|
|||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseAntiforgery();
|
app.UseAntiforgery();
|
||||||
app.UseForwardedHeaders();
|
|
||||||
|
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
@@ -124,11 +118,12 @@ app.MapStaticAssets();
|
|||||||
|
|
||||||
app.MapGet("/auth/login", (string redirectUri = "/") =>
|
app.MapGet("/auth/login", (string redirectUri = "/") =>
|
||||||
Results.Challenge(new AuthenticationProperties { RedirectUri = redirectUri }, [OpenIdConnectDefaults.AuthenticationScheme]));
|
Results.Challenge(new AuthenticationProperties { RedirectUri = redirectUri }, [OpenIdConnectDefaults.AuthenticationScheme]));
|
||||||
|
|
||||||
app.MapGet("/auth/logout", async (HttpContext context) =>
|
app.MapGet("/auth/logout", async (HttpContext context) =>
|
||||||
{
|
{
|
||||||
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
|
||||||
string currentBaseUrl = $"{context.Request.Scheme}://{context.Request.Host}{context.Request.PathBase}/";
|
string currentBaseUrl = $"https://{context.Request.Host}{context.Request.PathBase}/";
|
||||||
|
|
||||||
await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties
|
await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user