Skip to content

Extend OAuth provider configuration object to include a token refresh handler #4902

Closed
@essential-randomness

Description

@essential-randomness

Description 📓

The OAuth provider configuration object includes options (e.g. authorization, token, and userinfo) to configure how each provider handles the various stages of the OAuth flow.

While a mechanism for token rotation is explained in the documentation, there is no way to contribute the token refresh code to the set of built-in OAuth providers. I believe allowing this configuration to be shared with other developers through a built-in mechanism would be incredibly beneficial to the users of this library, even if the token rotation is not automatically executed.

In short, my proposal would be to add the following option to the OAuth provider configuration object :

{
  // ...
  /**
   * Endpoint that refreshes OAuth tokens and returns a new `access_token` and `refresh_token`.
   */
  refresh: EndpointHandler<
      RefreshParams,
      {
        // unsure about what goes here
      },
      { tokens: TokenSet }
  >;
  // ...
}

where RefreshParams would be something like:

interface RefreshParams {
  request_uri?: string;
  grant_type?: string;
  // Possibly more
}

This would allow developers to share the code for OAuth token refresh with the community. I don't foresee specific issues with such an extension.

Note that while I likely won't have time to implement a full automatic refresh flow, I'd be willing to contribute this specific extension (and a couple configurations for existing providers) as long as someone can offer help figuring out the right method signature.

How to reproduce ☕️

N/A

Contributing 🙌🏽

Yes, I am willing to help implement this feature in a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    adaptersChanges related to the core code concerning database adapterscoreRefers to `@auth/core`enhancementNew feature or requesthelp-neededThe maintainer needs help due to time constraint/missing knowledgeprovidersstaleDid not receive any activity for 60 days

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions