UNPKG

koas-security

Version:

Koas security checks if a request matches the security requirement of an operation. For example, given the following partial OpenAPI document:

19 lines (18 loc) 615 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseAuthorizationHeader = void 0; const authorizationRegExp = /^(\S+) (.*)$/; /** * Patse the authorization token from the Koa context. * * @param ctx - The Koa context containing the token. * @returns A tuple containing the type and value of the authorization header. */ function parseAuthorizationHeader(ctx) { const match = authorizationRegExp.exec(ctx.header.authorization); if (!match) { return ['', null]; } return match.slice(1); } exports.parseAuthorizationHeader = parseAuthorizationHeader;