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<PaginatedResourceResponse<OauthAccessToken[]>>;
getUserOauthAccessToken() parameters
| Name | Type | Description |
|---|---|---|
userId | string | The ID of the user to retrieve. |
provider | oauth_${OAuthProvider} | The OAuth provider to retrieve the access token for. |
getUserOauthAccessToken() example
In this example, you can see that the returned PaginatedResourceResponse includes data, which is an array of OauthAccessToken objects, and totalCount, which indicates the total number of access tokens for the specified user.
const userId = 'user_2bxfCJOe0Ocd8DNe9hFN3EXvfOu'; const provider = 'oauth_google'; const response = await clerkClient.users.getUserOauthAccessToken(userId, provider); console.log(response); /* In this example, you can see that data is an array of OauthAccessToken objects, and is populated with one OauthAccessToken. { data: [ _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 } ], totalCount: 1 } */
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.