Merge pull request 'Forcing https' (#14) from notifications into master
Reviewed-on: #14
This commit was merged in pull request #14.
This commit is contained in:
+6
-16
@@ -65,26 +65,16 @@ builder.Services.AddAuthentication(options =>
|
||||
RoleClaimType = "groups"
|
||||
};
|
||||
|
||||
options.Events = new OpenIdConnectEvents
|
||||
builder.Services.AddOptions<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme).Configure(options =>
|
||||
{
|
||||
OnRedirectToIdentityProviderForSignOut = async callbackContext =>
|
||||
options.Events.OnRedirectToIdentityProvider = context =>
|
||||
{
|
||||
var request = callbackContext.Request;
|
||||
string currentBaseUrl = $"{request.Scheme}://{request.Host}{request.PathBase}/";
|
||||
context.ProtocolMessage.RedirectUri = context.ProtocolMessage.RedirectUri.Replace("http://", "https://");
|
||||
|
||||
callbackContext.ProtocolMessage.PostLogoutRedirectUri = currentBaseUrl;
|
||||
|
||||
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;
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||
{
|
||||
@@ -128,7 +118,7 @@ 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