Skip to content

Client support for refresh and access tokens #2113

Closed

Description

@SandPod

Is your feature request related to a problem? Please describe.
Serverpod aims to support JWT token authentication, and this requires support for access and refresh tokens, as specified by the OAuth 2.0 standard.

Refresh and access tokens should be integrated into the Serverpod client and automatically handled. The client should be able to detect when an access token is outdated and request a new one using any stored refresh token.

Describe the solution you'd like

Storage of refresh and access tokens

The authentication key manager is currently designed only to support a single authentication key. Therefore, it must be expanded to support managing an optimal refresh token.

If no refresh token is configured, the refreshing of the access token should be disabled.

Configurable refresh token request

To update an access token, a call towards a refresh token endpoint containing the refresh token needs to be made.

To support custom refresh token schemes (for example, a centralized authentication server for multiple applications), it should be possible to configure how the refresh token request looks and where it is sent.

This should configured directly in the client.

If no refresh token request is configured, the refreshing of access tokens should be disabled.

Automatic renewal of access token

The following preconditions need to be satisfied to enable the automatic renewal of an access token:

  1. A refresh token is stored.
  2. A refresh token endpoint is configured.

If a request to an authenticated endpoint responds with a 401 HTTP status code, the automatic renewal of the access token should be triggered and the old access token should be discarded.

When triggered, a call is made to the configured refresh token endpoint containing the refresh token. If an access token is returned, it should be stored for future use.

If the server rejects the refresh token, it should be discarded.

Automatic call retry when the access token is updated

If an access token renewal succeeds, the client should automatically retry the call to the authenticated endpoint.

Describe alternatives you've considered

Additional context
With the Serverpod authentication module, no additional configuration should be required to get authentication working. That is, reasonable defaults that work with the authentication module should exist.

Special consideration should be taken to how discarding access and refresh tokens influence the logged-in state of the application.

Related issues:

Activity

  1. added
    enhancement
    on Apr 8, 2024
  2. moved this to Version 2.0 - Essentials 🔥 in Serverpod Frameworkson Apr 8, 2024
  3. moved this from Version 2.0 - Essentials 🔥 to Version 2.0 - Priority 🌟 in Serverpod Frameworkson May 21, 2024
  4. moved this from Next 🌟 to Later 🥳 in Serverpod Frameworkson Jul 1, 2024
  5. added
    area: authentication
    on Jul 8, 2024
  6. marcelomendoncasoares commented on Mar 26, 2026

    @marcelomendoncasoares
    Collaborator

    Closing since this was done during the implementation of JWT support for Serverpod 3.0 new auth.

  7. moved this from Backlog 🗂️ to Done 🚀 in Serverpod Frameworkson Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: authenticationenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions