From 496e11b5eb3b8996d3692e455a2bcd70bb07fc47 Mon Sep 17 00:00:00 2001 From: Joshua Nitschke <33307206+JoshuaNitschke@users.noreply.github.com> Date: Mon, 28 Oct 2024 00:32:51 -0700 Subject: [PATCH] chore: allow proper logout in examples (#929) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christoph Bühler --- .../Pages/Authenticated.cshtml.cs | 9 ++++++--- .../Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml | 13 +++++++++++++ .../Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml.cs | 7 +++++++ examples/Zitadel.AspNet.AuthN/Program.cs | 1 + 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml create mode 100644 examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml.cs diff --git a/examples/Zitadel.AspNet.AuthN/Pages/Authenticated.cshtml.cs b/examples/Zitadel.AspNet.AuthN/Pages/Authenticated.cshtml.cs index 559492a7..62bbde94 100644 --- a/examples/Zitadel.AspNet.AuthN/Pages/Authenticated.cshtml.cs +++ b/examples/Zitadel.AspNet.AuthN/Pages/Authenticated.cshtml.cs @@ -8,9 +8,12 @@ namespace Zitadel.AspNet.AuthN.Pages; [Authorize] public class Authenticated : PageModel { - public async Task 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" } + ); } } diff --git a/examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml b/examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml new file mode 100644 index 00000000..4db4bbe4 --- /dev/null +++ b/examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml @@ -0,0 +1,13 @@ +@page +@model LoggedOutModel + + + + Logged out + + +
+

You are now logged out.

+
+ + diff --git a/examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml.cs b/examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml.cs new file mode 100644 index 00000000..f70d8a77 --- /dev/null +++ b/examples/Zitadel.AspNet.AuthN/Pages/LoggedOut.cshtml.cs @@ -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 { } diff --git a/examples/Zitadel.AspNet.AuthN/Program.cs b/examples/Zitadel.AspNet.AuthN/Program.cs index 6dbf9f60..d2ecb032 100644 --- a/examples/Zitadel.AspNet.AuthN/Program.cs +++ b/examples/Zitadel.AspNet.AuthN/Program.cs @@ -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(