-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Blazor new AuthenticationState - consider event for expiry #11415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can override |
@campersau isn't that still polling? And wouldn't that require paramaters to be changing for that poll to happen? If the user left the page open for 5 minutes without doing anything on the page, how would components know to do a poll? |
I was thinking if |
I have noticed that the |
Yes, that will propergate the new |
@campersau ah I see how it fit's together now, thank you. I assume |
@dazinator yes, it does. |
Is your feature request related to a problem? Please describe.
Task<AuthenticationState>
is a new cascading parameter in blazor apps that allows downstream components access to the current authentication state of the user.In my blazor client application, users authentication sessions have a sliding expiry.
When the user's session expires, I'd like all downstream components to be notified that the authentication state has changed, so that they have an option to re-render - potentially an "unauthenticated view" for their content.
Today, I can implement a custom
AuthenticationStateProvider
that returns theAuthenticationState
based on my own 3 minute sliding cache of the users JWT token - and this works fine - the downstream components get theAuthenticationState
and the user is either authenticated or not authenticated.However, suppose the user is initially authenticated, but then after doing nothing on the site for 3 minutes, their authentication token expires. My custom authentication mechanism is able to raise an event when this happens, and my
AuthenticationStateProvider
will now return an unauthenticated principle when it is next asked for theAuthenticationState
. However downstream components are not able to be notified that the authentication state has Jjust changed - instead they must each poll the cascadedTask<AuthenticationState>
periodically. Having each component poll is not very efficient, and depending on the timing of each poll, some components may detect and re-render before others resulting in a bit of a haphazzard UI.I've considered tying
Describe the solution you'd like
What I'd like to see is a way for downstream components to be notified of authentication state change, in a way that doesn't require them to poll.
Describe alternatives you've considered
I've considered injecting a custom service into each downstream component, that bypasses
AuthenticationStateProvider
and directly couples them to my JWT token management system, which will notify them when the JWT token expires. I don't like this because it couples otherwise reusable components to my specific authentication mechanism. Even if I injected a generic Event / Message Bus / IPubSub service to decouple the components from my specific authentication mechanism, id still then be coupling them to that service. If I wanted to re-use those components in other apps, they's have to also adopt whatever service that was. This feels nasty,The text was updated successfully, but these errors were encountered: