This commit is contained in:
+12
-7
@@ -65,15 +65,18 @@ builder.Services.AddAuthentication(options =>
|
|||||||
RoleClaimType = "groups"
|
RoleClaimType = "groups"
|
||||||
};
|
};
|
||||||
|
|
||||||
builder.Services.AddOptions<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme).Configure(options =>
|
options.Events = new OpenIdConnectEvents
|
||||||
{
|
{
|
||||||
options.Events.OnRedirectToIdentityProvider = context =>
|
OnRedirectToIdentityProvider = context =>
|
||||||
{
|
{
|
||||||
context.ProtocolMessage.RedirectUri = context.ProtocolMessage.RedirectUri.Replace("http://", "https://");
|
var fallbackUri = context.ProtocolMessage.RedirectUri;
|
||||||
|
|
||||||
|
if (fallbackUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
|
||||||
|
context.ProtocolMessage.RedirectUri = fallbackUri.Replace("http://", "https://", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
};
|
}
|
||||||
});
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
@@ -90,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);
|
||||||
@@ -105,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();
|
||||||
@@ -114,6 +118,7 @@ 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);
|
||||||
|
|||||||
Reference in New Issue
Block a user