//native
type Vercel = {
token: string;
};
/**
* SSO Token Exchange
* During the autorization process, Vercel sends the user to the provider [redirectLoginUrl](https://vercel.
*/
export async function main(
auth: Vercel,
body: {
code: string;
state?: string;
client_id: string;
client_secret: string;
redirect_uri?: string;
},
) {
const url = new URL(`https://api.vercel.com/v1/integrations/sso/token`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago