Skip to main content

getUserOauthAccessToken()

Gets the corresponding for a user that has previously authenticated with the given 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 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 get the OAuth access tokens for.

  • Name
    provider
    Type
    OAuthProvider
    Description

    The OAuth provider to get the access tokens for. If using a custom OAuth provider, prefix the provider name with custom_ (e.g. oauth_custom_google).

Note

Using clerkClient varies based on the SDK you're using. Refer to the overview for usage details, including guidance on how to access the userId and other properties.

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