Description
Describe the issue
In the Blazor Web App (Interactive server), the token refresh process occurs during the OnValidatePrincipal cookie event. This event is triggered if the access token is less than 5 minutes away from expiration. However, this event only executes during a complete page reload.
A potential issue arises when a user reloads the page 6 minutes prior to the access token's expiration. In this case, the OnValidatePrincipal event does not refresh the token. If the user continues to interact with the website without a full page reload, the token may expire after 6 minutes. Consequently, all subsequent API requests are rejected. The question is how to handle such a scenario.
To Reproduce
- Set up an OIDC server with a short access token lifetime (e.g., 30 seconds) for demonstration purposes.
- Create a protected API that validates the access token.
- Use the BlazorWebAppOidc sample as the client.
- Add a simple action to BlazorWebAppOidc that requests a protected API endpoint.
- Refresh the BlazorWebAppOidc app, wait for 30 seconds, and without refreshing the app again, try to request the API.
Expected behavior
The common solution to this issue is to refresh the token during an HTTP request with a DelegatingHandler. However, in our scenario, we cannot override the cookie inside the DelegatingHandler. The expected behavior, therefore, is to be able to refresh tokens in the DelegatingHandler while storing them in cookies. If there's a way to override the cookie inside the DelegatingHandler that I'm not aware of, that could also be a potential solution.
Issue Details
⚠ Do not edit this section. It is required for issue processing.
- Content Source: dotnet/blazor-samples
- GitHub Login: @guardrex