UNPKG

@graphql-yoga/plugin-jwt

Version:
32 lines (31 loc) 1.12 kB
import { extractFromHeader } from './utils.js'; export function normalizeConfig(input) { if (input.singingKeyProviders.length === 0) { throw new TypeError('You must provide at least one signing key provider. Please verify your `singingKeyProviders` configuration.'); } const extendContextFieldName = input.extendContext === false ? null : input.extendContext === undefined || input.extendContext === true ? 'jwt' : input.extendContext; const tokenLookupLocations = input.tokenLookupLocations ?? []; if (tokenLookupLocations.length === 0) { tokenLookupLocations.push(extractFromHeader({ name: 'Authorization', prefix: 'Bearer', })); } return { singingKeyProviders: input.singingKeyProviders, tokenLookupLocations, tokenVerification: input.tokenVerification ?? { algorithms: ['RS256', 'HS256'], }, reject: { missingToken: true, invalidToken: true, ...input.reject, }, extendContextFieldName, }; }