//native
type Clerk = {
apiKey: string;
};
/**
* Retrieve the OAuth access token of a user
* Fetch the corresponding OAuth access token for a user that has previously authenticated with a particular OAuth provider.
For OAuth 2.0, if the access token has expired and we have a corresponding refresh token, the access token will be refreshed transparently the new one will be returned.
*/
export async function main(auth: Clerk, user_id: string, provider: string) {
const url = new URL(
`https://api.clerk.com/v1/users/${user_id}/oauth_access_tokens/${provider}`,
);
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago