File

src/registrar/generated/core/auth.ts

Index

Properties

Properties

in
in: "header" | "query" | "cookie"
Default value : 'header'
Type : "header" | "query" | "cookie"
Optional

Which part of the request do we use to send the auth?

name
name: string
Default value : 'Authorization'
Type : string
Optional

Header or query parameter name.

scheme
scheme: "basic" | "bearer"
Type : "basic" | "bearer"
Optional
type
type: "apiKey" | "http"
Type : "apiKey" | "http"
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';
    /**
     * 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;
};

results matching ""

    No results matching ""