Skip to content

Clarify intended procedure for detecting when a new access token has been generated and how/whether to store it #3568

Open

Description

@calculuschild

Please make sure you have searched for information in the following guides.

Documentation Request

When an access token is expired, performing an API request will automatically use the refresh token to fetch a new access token. However, this does not trigger the on('tokens) event; this only fires on the first authentication.

What is not explained clearly in the docs then, is how the new access token is meant to be detected so that it can be stored and reused for its validity period. Otherwise the new access token may be lost and users hit 401 Invalid Credentials errors in subsequent requests.

Is the intent that after each API call, we manually check the oAuth2Client for a new access token via oAuth2Client.credentials.access_token? I.e., add manual token checking logic after each API call? If this is the case, can explicit instructions be added that something like this is the intended approach?

Or is there some other event similar to tokens we can listen for on the oAuth2Client that will automatically trigger upon receiving an updated access token? (If not, can that feature be added?)

Perhaps the access token is not meant to be stored at all? Discarded after each request? But then we are fetching new access tokens for every request after the first hour.

Activity

  1. changed the title [-]How to detect when a new access token has been generated[/-] [+]Expected procedure for detecting when a new access token has been generated[/+] on Oct 1, 2024
  2. changed the title [-]Expected procedure for detecting when a new access token has been generated[/-] [+]Clarify intended procedure for detecting when a new access token has been generated[/+] on Oct 1, 2024
  3. changed the title [-]Clarify intended procedure for detecting when a new access token has been generated[/-] [+]Clarify intended procedure for detecting when a new access token has been generated and how/whether to store it[/+] on Oct 10, 2024
  4. added
    type: docsImprovement to the documentation for an API.
    size: mPull request size is medium.
    on Feb 4, 2025
  5. eanyanwu commented on Feb 25, 2026

    @eanyanwu

    👋🏾 just another user of this package.

    I think the docs are misleading. The code seems to always emit the tokens event on all token refreshes.

    I think the docs are trying to say that only the first authorization (i.e. where the user grants permissions) will have the refresh_token field. All subsequent refreshes just have the access_token field.

    I have an app I'm currently working on and this seems to be the behavior I'm seeing.

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

    size: mPull request size is medium.type: docsImprovement to the documentation for an API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions