Skip to content

Commit

Permalink
feat: Improved/simplified sign out.
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-meier committed Oct 25, 2024
1 parent 0d2aaa6 commit 366874b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/Chrono/ConfigureSecurity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public static void AddWebUiSecurityServices(this IServiceCollection services, IC
//options.Cookie.SameSite = SameSiteMode.Strict;

options.Cookie.Name = configuration["IdentityProvider:CookieName"];
options.Events.OnSigningOut = e => e.HttpContext.RevokeUserRefreshTokenAsync();
})
.AddOpenIdConnect(options =>
{
Expand Down
19 changes: 6 additions & 13 deletions src/Chrono/Features/Users/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,26 @@
using Chrono.Shared.Api;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Chrono.Features.Users;

[Authorize]
[ApiExplorerSettings(IgnoreApi = true)]
public class LoginController(IConfiguration config) : ApiControllerBase
public class LoginController : ApiControllerBase
{
[HttpGet]
public async Task<ActionResult> Get([FromQuery] string redirectUrl, [FromQuery] string sign = "in")
public ActionResult Get([FromQuery] string redirectUrl, [FromQuery] string sign = "in")
{
if (sign == "in")
{
return Redirect(redirectUrl);
}

SignOut("cookie", "oidc");

// To ensure that all auth. cookies are being deleted, since ASP.NET Core uses the ChunkingCookieManager for cookie authentication by default.
new ChunkingCookieManager().DeleteCookie(HttpContext, config["IdentityProvider:CookieName"]!,
new CookieOptions());

var idToken = await HttpContext.GetTokenAsync("id_token");
var logoutUrl = config["IdentityProvider:LogoutUrl"];

return Redirect(
$"{logoutUrl}?id_token_hint={idToken}&post_logout_redirect_uri={HttpUtility.UrlEncode(redirectUrl)}");
return SignOut(new AuthenticationProperties { RedirectUri = redirectUrl },
CookieAuthenticationDefaults.AuthenticationScheme,
OpenIdConnectDefaults.AuthenticationScheme);
}
}
1 change: 0 additions & 1 deletion src/Chrono/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"CookieName": "ChronoAuth",
"Authority": "https://<TODO>.auth0.com/",
"JwksUri": "https://<TODO>.auth0.com/.well-known/jwks.json",
"LogoutUrl": "https://<TODO>.auth0.com/oidc/logout",
"ClientId": "<TODO>",
"ClientSecret": "<TODO>"
},
Expand Down

0 comments on commit 366874b

Please sign in to comment.