This repository has been archived on 2024-06-14. You can view files and clone it, but cannot push or open issues or pull requests.
icynet-admin/lib/api/remote.ts

25 lines
699 B
TypeScript
Raw Normal View History

2022-09-12 19:31:58 +00:00
import { API_URL, CLIENT_ID, CLIENT_SECRET, TOKEN_URL } from '../constants';
2022-08-29 18:09:28 +00:00
export const getUserInfo = async (accessToken: string) =>
2022-09-12 19:31:58 +00:00
fetch(`${API_URL}/user`, {
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
}).then((res) => res.json());
2022-08-29 18:09:28 +00:00
2022-09-12 19:31:58 +00:00
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());