I've implemented a custom AuthenticationStateProvider. For some reason, I cannot debug this method below, which should run whenever you boot up the app. This is causing me not to know why my token is not being retrieved.
I'm fairly certain this method is being called, because the Task.Delay does delay the app from appearing.
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
//await Task.Delay(90000000);
//Runs everytime the app reloads/initial load.
var savedToken = await _localStorage.GetItemAsync<TokenResponse>("TokenVal");
if (string.IsNullOrWhiteSpace(savedToken?.access_token))
{
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
}
if (!await ValidateCurrentToken(savedToken.access_token))
{
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
}
return await MarkUserAsAuthenticated(savedToken.access_token);
}
Registered it in Program.cs
builder.Services.AddAuthorizationCore();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddScoped<AuthenticationStateProvider, TVAuthenticationStateProvider>();
I can login, takes me into the app ,authenticated. I refresh and it takes me back to login, and this method is never hit, which would grab the token, validate it and not make me login again. I've got this working fine on a Blazor Server side app.
Here is my App.razor too, I've got CascadingAuthenticationState setup..
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<Item.Shared.Utilities.LoginRedirect></Item.Shared.Utilities.LoginRedirect>
</NotAuthorized>
<Authorizing>
Hello?
<Chase Center="true" Color="#235273" Size="150px" style="margin-top: 10%;" />
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address..</p>
</LayoutView>
</NotFound>
</Router> </CascadingAuthenticationState>