Function refreshAccessToken

  • Refreshes an expired access token using the refresh token.

    Parameters

    • clientId: string

      The client ID of your application.

    • clientSecret: string

      The client secret of your application.

    • refreshToken: string

      The refresh token obtained during the initial authorization process.

    • scopes: string[] = []

      Optional. The scopes to request for the new access token. Defaults to the original scopes.

    Returns Promise<AccessToken>

    A promise resolving to a new AccessToken object.

    Access tokens eventually expire, but a refresh token can be used to obtain a new one without requiring user reauthorization. This function performs the necessary call to refresh the token and return a new AccessToken object.

    HttpError If an error occurs during the request, such as an invalid refresh token.

    try {
    const token = await refreshAccessToken(
    'your-client-id',
    'your-client-secret',
    'refresh-token-here',
    ['oauth-user-show', 'oauth-donation-index']
    );

    console.log('New Access Token:', token.accessToken);
    } catch (e) {
    console.error('Failed to refresh access token:', e);
    }