I am working on a Blazor WASM application that uses B2C to authenticate the users and am having trouble getting the access token to refresh when I set the login mode to 'Redirect' rather than 'Popup'. I've pulled back my code to the absolute minimum which is essentially the tutorial at: https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-azure-active-directory-b2c?view=aspnetcore-5.0
As per Microsoft's examples, I wrap my http calls in a try/catch block as below with the intention that if the Access token expires, a new access token is retrieved and the page reloaded:
try
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
}
For purpose of testing, I have set my Access Token timeout to 10 minutes and note that when this expires (and I had used the default Login mode of 'Popup'), a new Access token is obtained and the current page is returned to.
If however I change the LoginMode to 'Redirect' rather than 'Popup' and repeat the test, I receive the following error message within the address bar:
...authentication/login-failed?message=State%20mismatch%20error.%20Please%20check%20your%20network.%20Continued%20requests%20may%20cause%20cache%20overflow.
Interestingly though, it does appear to have updated the Access token as a quick flick between pages and I am able to retrieve the data. Has anyone else experienced this or have any thoughts how to resolve this?