From 70d13df1ccb5e8270133c33a72e4e0cf447a2377 Mon Sep 17 00:00:00 2001 From: damienbod Date: Tue, 3 Dec 2024 21:16:13 +0100 Subject: [PATCH] OpenIdConnectDefaults.AuthenticationScheme --- ui/HostingExtensions.cs | 5 +++-- ui/Pages/Logout.cshtml.cs | 14 ++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ui/HostingExtensions.cs b/ui/HostingExtensions.cs index 41994c5..3d5702c 100644 --- a/ui/HostingExtensions.cs +++ b/ui/HostingExtensions.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.IdentityModel.JsonWebTokens; using Microsoft.IdentityModel.Logging; using Microsoft.IdentityModel.Tokens; @@ -19,7 +20,7 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = "oidc"; + options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => { @@ -30,7 +31,7 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde await e.HttpContext.RevokeRefreshTokenAsync(); }; }) - .AddOpenIdConnect("oidc", options => + .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options => { options.Authority = "https://localhost:5001"; options.ClientId = "web-dpop"; diff --git a/ui/Pages/Logout.cshtml.cs b/ui/Pages/Logout.cshtml.cs index 5f4c9a5..522b603 100644 --- a/ui/Pages/Logout.cshtml.cs +++ b/ui/Pages/Logout.cshtml.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -9,10 +10,15 @@ namespace WebCodeFlowPkceClient.Pages; [Authorize] public class LogoutModel : PageModel { - public async Task OnGetAsync() + public IActionResult OnGetAsync() { - await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); - - return Redirect("/SignedOut"); + return SignOut(new AuthenticationProperties + { + RedirectUri = "/SignedOut" + }, + // Clear auth cookie + CookieAuthenticationDefaults.AuthenticationScheme, + // Redirect to OIDC provider signout endpoint + OpenIdConnectDefaults.AuthenticationScheme); } } \ No newline at end of file