Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
58bcdab32a | 2 years ago |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 793 B After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 802 B |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 884 B After Width: | Height: | Size: 685 B |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@ -0,0 +1,51 @@ |
|||||||
|
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) |
||||||
|
} |
||||||