Description
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 the AuthenticationState
based on my own 3 minute sliding cache of the users JWT token - and this works fine - the downstream components get the AuthenticationState
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 the AuthenticationState
. However downstream components are not able to be notified that the authentication state has Jjust changed - instead they must each poll the cascaded Task<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,