-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Hello.
My apologies if I've missed anything in the docs and / or previous issues regarding this topic - I have looked fairly thoroughly but I can't find anything concrete.
Whilst testing an application that I'm developing, I've noticed something and I'd appreciate some guidance from Microsoft (or anyone who's previously encountered this) about what to do.
I'm able to re-create the behaviour on a brand new File -> New Blazor Server app with "Individual authentication" using the .NET template - so I'm very confident it's not a quirk of my application.

Below, I've linked to a sample repo to provide as much context as I can.
The master branch is simply the output of the File -> New operation. No changes at all.
Then, in a branch named IdentityRevalidatingAuthenticationStateProviderChanges I've made a very simple change to simulate a user's session being invalidated. You can see that this is the sole change.
Running that branch, I've ran the migration, created a user, logged in, and then let the IdentityRevalidatingAuthenticationStateProvider invalidate my session on the circut - which I understand is the point of it as detailed here.
The result is the screenshot you can see below. The user appears to be logged out as far as Blazor is concerned, yet their "Application" cookie from ASP.NET identity persists:

This means that a user can click login again, or, they can just refresh / open the website in another tab and be automatically logged back in because the cookie is sent by the browser. Which is obvioulsy not ideal for a number of reasons.
I've got a fix in place, but it feels really dirty. However, I can't find examples (or think) of a better solution.
Taking advantage of the routing, I've updated the RedirectToLogin component to post a hidden form to the Logout endpoint and updated the endpoint to return a TypedResults.SignOut for the ApplicationScheme. This seems to work without negative implications but I feel like there has to be a better way to solve the problem.
I've had a good look through the docs and I can see there's plenty of examples of how to handle these situations with Blazor WASM, or using a client and reverse proxying via YARP but there seems to be limited examples when using "pure" Blazor Server.
Is anyone able to suggest or share something to solve this problem in a more elegant manner please?