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[]>;
- Name
userId
- Type
string
- Description
The ID of the user to retrieve.
- Name
provider
- Type
oauth_${OAuthProvider}
- Description
The OAuth provider to retrieve the access token for.
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 for more details.
Feedback
Last updated on