Skip to main content
Docs

getUserOauthAccessToken()

Retrieves the corresponding for a user that has previously authenticated with a particular OAuth provider. Returns a PaginatedResourceResponse object with a data property that contains an array of OauthAccessToken objects, and a totalCount property that indicates the total number of OAuth access tokens in the system for the specified user and provider.

function getUserOauthAccessToken(
  userId: string,
  provider: `${OAuthProvider}`,
): Promise<PaginatedResourceResponse<OauthAccessToken[]>>
  • Name
    userId
    Type
    string
    Description

    The ID of the user to retrieve the OAuth access token for.

  • Name
    provider
    Type
    ${OAuthProviderJavaScript Icon}
    Description

    The OAuth provider to retrieve the access token for. If using a custom OAuth provider, prefix the provider name with custom_ (e.g., custom_foo).

Note

Using clerkClient varies based on your framework. Refer to the JS Backend SDK overviewClerk Icon for usage details, including guidance on how to access the userId and other propertiesClerk Icon.

const userId = 'user_123'

const provider = 'google'

const response = await clerkClient.users.getUserOauthAccessToken(userId, provider)

You can also explore the example that demonstrates how this method retrieves a social provider's OAuth access token, enabling access to user data from both the provider and Clerk.

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint GET/users/{user_id}/oauth_access_tokens/{provider}. See the BAPI reference for more information.

Feedback

What did you think of this content?

Last updated on