Compare commits
6 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
8896df9f1f | 2 years ago |
|
|
10bca448dc | 2 years ago |
|
|
7a2423568a | 2 years ago |
|
|
ccb265cb2e | 2 years ago |
|
|
3152372c39 | 2 years ago |
|
|
4e43b9aea8 | 2 years ago |
@ -1,51 +0,0 @@ |
|||||||
import { AUTH_SERVICE } from 'config' |
|
||||||
import { ClientIds } from 'config/clients/types' |
|
||||||
|
|
||||||
export type TokenFailedResponse = { |
|
||||||
error?: { |
|
||||||
code: number, |
|
||||||
message: string, |
|
||||||
}, |
|
||||||
ok: false, |
|
||||||
} |
|
||||||
|
|
||||||
type TokenResponse = { |
|
||||||
access_token: string, |
|
||||||
id_token: string, |
|
||||||
refresh_token: string, |
|
||||||
} |
|
||||||
|
|
||||||
type TokenProps = { |
|
||||||
client_id: ClientIds, |
|
||||||
email?: 'string', |
|
||||||
grant_type?: 'password' | 'refresh_token', |
|
||||||
id_token?: 'string', |
|
||||||
password?: 'string', |
|
||||||
refresh_token: string, |
|
||||||
} |
|
||||||
|
|
||||||
export const getCredentials = async ({ |
|
||||||
client_id, |
|
||||||
grant_type = 'refresh_token', |
|
||||||
refresh_token, |
|
||||||
}: TokenProps): Promise<TokenResponse> => { |
|
||||||
const url = new URL(`${AUTH_SERVICE}/token`) |
|
||||||
|
|
||||||
const credetials = await fetch(url, { |
|
||||||
body: JSON.stringify({ |
|
||||||
client_id, |
|
||||||
grant_type, |
|
||||||
refresh_token, |
|
||||||
}), |
|
||||||
headers: { |
|
||||||
'Content-Type': 'application/json', |
|
||||||
}, |
|
||||||
method: 'POST', |
|
||||||
}) |
|
||||||
|
|
||||||
const body: TokenResponse | TokenFailedResponse = await credetials.json() |
|
||||||
|
|
||||||
if ('ok' in body) return Promise.reject(body.error) |
|
||||||
|
|
||||||
return Promise.resolve(body) |
|
||||||
} |
|
||||||
Loading…
Reference in new issue