/** * Validates the `authorization` header and returns the scheme and token * @param serviceAuthScheme Auth scheme used for headless inter-service calls * @param authorizationHeader The `authorization` header */ export const validateAuthHeader = ( serviceAuthScheme: string, authorizationHeader: string ) => { const [scheme, token] = authorizationHeader.split(' '); if (!token) throw new Error('Token not specified in Authorization header'); const validSchemes = ['Bearer', serviceAuthScheme]; if (validSchemes.includes(scheme)) return { scheme, token }; throw new Error('Invalid auth scheme provided'); };