fork of hey-api/openapi-ts because I need some additional things
1// This file is auto-generated by @hey-api/openapi-ts
2
3export type AuthToken = string | undefined;
4
5export interface Auth {
6 /**
7 * Which part of the request do we use to send the auth?
8 *
9 * @default 'header'
10 */
11 in?: 'header' | 'query' | 'cookie';
12 /**
13 * Header or query parameter name.
14 *
15 * @default 'Authorization'
16 */
17 name?: string;
18 scheme?: 'basic' | 'bearer';
19 type: 'apiKey' | 'http';
20}
21
22export const getAuthToken = async (
23 auth: Auth,
24 callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
25): Promise<string | undefined> => {
26 const token =
27 typeof callback === 'function' ? await callback(auth) : callback;
28
29 if (!token) {
30 return;
31 }
32
33 if (auth.scheme === 'bearer') {
34 return `Bearer ${token}`;
35 }
36
37 if (auth.scheme === 'basic') {
38 return `Basic ${btoa(token)}`;
39 }
40
41 return token;
42};