mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
// Generated by @hey-api/openapi-ts.
|
|
// Do not edit this directory by hand; run npm run api:generate instead.
|
|
|
|
export type AuthToken = string | undefined;
|
|
|
|
export interface Auth {
|
|
/**
|
|
* Which part of the request do we use to send the auth?
|
|
*
|
|
* @default 'header'
|
|
*/
|
|
in?: 'header' | 'query' | 'cookie';
|
|
/**
|
|
* A unique identifier for the security scheme.
|
|
*
|
|
* Defined only when there are multiple security schemes whose `Auth`
|
|
* shape would otherwise be identical.
|
|
*/
|
|
key?: string;
|
|
/**
|
|
* Header or query parameter name.
|
|
*
|
|
* @default 'Authorization'
|
|
*/
|
|
name?: string;
|
|
scheme?: 'basic' | 'bearer';
|
|
type: 'apiKey' | 'http';
|
|
}
|
|
|
|
export const getAuthToken = async (
|
|
auth: Auth,
|
|
callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
|
|
): Promise<string | undefined> => {
|
|
const token = typeof callback === 'function' ? await callback(auth) : callback;
|
|
|
|
if (!token) {
|
|
return;
|
|
}
|
|
|
|
if (auth.scheme === 'bearer') {
|
|
return `Bearer ${token}`;
|
|
}
|
|
|
|
if (auth.scheme === 'basic') {
|
|
return `Basic ${btoa(token)}`;
|
|
}
|
|
|
|
return token;
|
|
};
|