Skip to content

Commit

Permalink
chore: allow proper logout in examples (#929)
Browse files Browse the repository at this point in the history
Co-authored-by: Christoph Bühler <buehler@users.noreply.github.com>
  • Loading branch information
JoshuaNitschke and buehler authored Oct 28, 2024
1 parent 5516d9e commit 496e11b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/Zitadel.AspNet.AuthN/Pages/Authenticated.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ namespace Zitadel.AspNet.AuthN.Pages;
[Authorize]
public class Authenticated : PageModel
{
public async Task<IActionResult> OnPostAsync()
public async Task OnPostAsync()
{
await HttpContext.SignOutAsync();
return RedirectToPage("/Index");
await HttpContext.SignOutAsync("Identity.External"); // Options: signs you out of ZITADEL entirely, without this you may not be reprompted for your password.
await HttpContext.SignOutAsync(
ZitadelDefaults.AuthenticationScheme,
new AuthenticationProperties { RedirectUri = "http://localhost:8080/loggedout" }
);
}
}
13 changes: 13 additions & 0 deletions examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@page
@model LoggedOutModel

<html lang="en">
<head>
<title>Logged out</title>
</head>
<body>
<div>
<p>You are now logged out.</P>
</div>
</body>
</html>
7 changes: 7 additions & 0 deletions examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Zitadel.AspNet.AuthN.Pages;

public class LoggedOutModel : PageModel { }
1 change: 1 addition & 0 deletions examples/Zitadel.AspNet.AuthN/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
o.Authority = "https://zitadel-libraries-l8boqa.zitadel.cloud/";
o.ClientId = "170088295403946241@library";
o.SignInScheme = IdentityConstants.ExternalScheme;
o.SaveTokens = true;
})
.AddExternalCookie()
.Configure(
Expand Down

0 comments on commit 496e11b

Please sign in to comment.