Skip to content

Refresh token during http request in Blazor Interactive Server with OIDC #267

Closed
@bpsc-wkubis

Description

@bpsc-wkubis

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

  1. Set up an OIDC server with a short access token lifetime (e.g., 30 seconds) for demonstration purposes.
  2. Create a protected API that validates the access token.
  3. Use the BlazorWebAppOidc sample as the client.
  4. Add a simple action to BlazorWebAppOidc that requests a protected API endpoint.
  5. 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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions