fork of hey-api/openapi-ts because I need some additional things
at feat/skip-token 41 lines 860 B view raw
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 = typeof callback === 'function' ? await callback(auth) : callback; 27 28 if (!token) { 29 return; 30 } 31 32 if (auth.scheme === 'bearer') { 33 return `Bearer ${token}`; 34 } 35 36 if (auth.scheme === 'basic') { 37 return `Basic ${btoa(token)}`; 38 } 39 40 return token; 41};