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
|
||||
{
|
||||
OnRedirectToIdentityProviderForSignOut = async callbackContext =>
|
||||
OnRedirectToIdentityProvider = context =>
|
||||
{
|
||||
var request = callbackContext.Request;
|
||||
string currentBaseUrl = $"{request.Scheme}://{request.Host}{request.PathBase}/";
|
||||
var fallbackUri = context.ProtocolMessage.RedirectUri;
|
||||
|
||||
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");
|
||||
|
||||
if (!string.IsNullOrEmpty(idToken)) callbackContext.ProtocolMessage.IdTokenHint = idToken;
|
||||
|
||||
if (callbackContext.ProtocolMessage.RedirectUri.StartsWith("http://"))
|
||||
{
|
||||
callbackContext.ProtocolMessage.RedirectUri = callbackContext.ProtocolMessage.RedirectUri.Replace("http://", "https://");
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -100,6 +93,8 @@ var scheduler = await schedulerFactory.GetScheduler(ShopSchedulerName);
|
||||
if (!scheduler!.IsStarted)
|
||||
await scheduler.Start();
|
||||
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
||||
@@ -115,7 +110,6 @@ app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages:
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAntiforgery();
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
@@ -124,11 +118,12 @@ app.MapStaticAssets();
|
||||
|
||||
app.MapGet("/auth/login", (string redirectUri = "/") =>
|
||||
Results.Challenge(new AuthenticationProperties { RedirectUri = redirectUri }, [OpenIdConnectDefaults.AuthenticationScheme]));
|
||||
|
||||
app.MapGet("/auth/logout", async (HttpContext context) =>
|
||||
{
|
||||
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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user