extractAuthToken (handlers/extractRequestAuth.ts)

webiny-js · packages/api-event-handler-aws/src/handlers/extractRequestAuth.ts · typescript · MIT
auth

Parses authentication tokens from HTTP headers, supporting custom headers, Authorization, and cookies.

// Source: https://github.com/webiny/webiny-js | License: MIT | Copyright Webiny Inc
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Header parsing shared by the API Gateway and Function URL auth/tenant decorators, so the two
 * transports can't drift on how a caller authenticates.
 */

export const WEBINY_AUTHORIZATION_HEADER = "x-webiny-authorization";

function parseCookieHeader(cookieHeader: string): Record<string, string> {
    return cookieHeader.split(";").reduce<Record<string, string>>((acc, pair) => {
        const idx = pair.indexOf("=");
        if (idx > 0) {
            acc[pair.slice(0, idx).trim()] = decodeURIComponent(pair.slice(idx + 1).trim());
        }
        return acc;
    }, {});
}

function getHeader(headers: Record<string, string> | undefin

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key