import { CLIENT_ID, CLIENT_SECRET, TOKEN_URL } from '../constants';
import { OAuth2TokenDto } from '../types/token-response.interface';
export async function fetchBearer<T>(
accessToken: string,
url: string,
...options: any[]
): Promise<T> {
return fetch(url, {
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
...options,
}).then((res) => res.json());
}
export async function fetchToken(code: string): Promise<OAuth2TokenDto> {
return fetch(TOKEN_URL, {
Authorization: `Basic ${Buffer.from(
`${CLIENT_ID}:${CLIENT_SECRET}`
).toString('base64')}`,
method: 'POST',
body: JSON.stringify({
grant_type: 'authorization_code',
code,
}),