Skip to Content
You are viewing a beta version of Clerk Docs
Visit the latest docs
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

getUserOauthAccessToken()

Retrieve the corresponding OAuth access token for a user that has previously authenticated with a particular OAuth provider.

function getUserOauthAccessToken: (userId: string, provider: `oauth_${OAuthProvider}`) => Promise<OauthAccessToken[]>;

Parameters

NameTypeDescription
userIdstringThe ID of the user to retrieve.
provideroauth_${OAuthProvider}The OAuth provider to retrieve the access token for.

Example

const userId = 'user_2bxfCJOe0Ocd8DNe9hFN3EXvfOu'; const provider = 'oauth_google'; const response = await clerkClient.users.getUserOauthAccessToken(userId, provider); console.log(response); /* [ _OauthAccessToken { provider: 'oauth_google', token: 'ya29...', publicMetadata: {}, label: null, scopes: [ 'email', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'openid', 'profile' ], tokenSecret: undefined } ] */

You can also explore the working 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(opens in a new tab) for more details.

Last updated on April 5, 2024

What did you think of this content?

Clerk © 2024