@graphql-yoga/plugin-jwt
Version:
jwt plugin for GraphQL Yoga.
39 lines (38 loc) • 1.5 kB
JavaScript
import { extractFromHeader } from './utils.js';
export function normalizeConfig(input) {
// TODO: remove this on next major version.
if (input.singingKeyProviders) {
if (input.signingKeyProviders) {
throw new TypeError('You are using both deprecated `singingKeyProviders` and its new replacement `signingKeyProviders` configuration. Please use only `signingKeyProviders`');
}
input.signingKeyProviders = input.singingKeyProviders;
}
if (!input.signingKeyProviders) {
throw new TypeError('You must provide at least one signing key provider. Please verify your `signingKeyProviders` 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 {
signingKeyProviders: input.signingKeyProviders,
tokenLookupLocations,
tokenVerification: input.tokenVerification ?? {
algorithms: ['RS256', 'HS256'],
},
reject: {
missingToken: true,
invalidToken: true,
...input.reject,
},
extendContextFieldName,
};
}