25 lines
699 B
TypeScript
25 lines
699 B
TypeScript
import { API_URL, CLIENT_ID, CLIENT_SECRET, TOKEN_URL } from '../constants';
|
|
|
|
export const getUserInfo = async (accessToken: string) =>
|
|
fetch(`${API_URL}/user`, {
|
|
headers: {
|
|
Authorization: `Bearer ${accessToken}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
}).then((res) => res.json());
|
|
|
|
export const getAccessToken = async (code: string) =>
|
|
fetch(TOKEN_URL, {
|
|
headers: {
|
|
Authorization: `Basic ${Buffer.from(
|
|
`${CLIENT_ID}:${CLIENT_SECRET}`
|
|
).toString('base64')}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
grant_type: 'authorization_code',
|
|
code,
|
|
}),
|
|
}).then((res) => res.json());
|