I am encountering an issue where my Blazor WebAssembly (WASM) application can initially access my access token with no problems, but after a few hours, it cannot refresh the token on mobile devices, whereas on my PC, it still works fine. The AccessToken result on mobile returns false, which I assume indicates that the website failed to get a new access token. It starts working again once I log out and log back in.
Here's my dependency injection:
builder.Services.AddHttpClient("WebAPI",
client => client.BaseAddress = new Uri(RestApiConnection.AttendanceURL))
.AddHttpMessageHandler<CustomAuthorizationMessageHandler>();
builder.Services.AddTransient<CustomAuthorizationMessageHandler>();
builder.Services.AddMsalAuthentication(options =>
{
builder.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication);
options.ProviderOptions.DefaultAccessTokenScopes.Add("api://custom/access_as_user");
options.ProviderOptions.Cache.CacheLocation = "localStorage";
});
This is where the exception is being thrown:
protected override async Task OnInitializedAsync()
{
var tokenResult = await TokenProvider.RequestAccessToken();
Console.WriteLine($"Access Result: {tokenResult?.TryGetToken(out Token)}");
Console.WriteLine($"Access Token: {Token?.Value}");
And the issue is that the Access Result is false.