I have been migrating a client-side Blazor WebAssembly app that I had previously built that used a custom AuthenticationStateProvider. I am updating it to use an OIDC identity provider server with Microsoft's off-the-shelf RemoteAuthenticationService and their AddOidcAuthentication() method.
With the old implementation the AuthenticationStateChanged event was fired both when the user signed in via the sign-in UI AND when the user was already signed in when they started the app and the authentication was simply silently verified. None of my code was doing this, so Microsoft's authentication framework must have been handling it.
After switching to Microsoft's OIDC support the AuthenticationStateChanged event is ONLY firing when the user signs in via the UI and does NOT fire when authentication is silently verified (auth is still valid, user starts the app).
I am trying to understand how to get this event to fire the way it used to (each time the app is started, the event is fired after authentication is resolved- whether that be a route through the sign-in UI, resolved against the OIDC server silently because the token is still valid, etc.).
My configuration of the OIDC auth subsystem is quite simple (points to Microsoft):
builder.Services.AddOidcAuthentication(options => {
// Configure our OIDC Identity Provider
options.ProviderOptions.Authority = "{OIDC-PROVIDER-AUTHORITY-URL}";
options.ProviderOptions.ClientId = "{OIDC-CLIENT-ID}";
options.ProviderOptions.ResponseMode = "query";
options.ProviderOptions.DefaultScopes.Add("email"); // openid and profile are already there by default
});
builder.Services.AddAuthorizationCore(options => {
options.AddPolicy("IsCustomUser", policy => policy.RequireClaim("custom_user", "true"));
options.AddPolicy("IsCustomAdmin", policy => policy.RequireClaim("custom_admin", "true"));
});
Any insights into how I can have the AuthenticationStateChanged event fire on "silent" auth verification as well?