Skip to content

Commit

Permalink
fix: Fixes for auto-detecting presence of authorization header.
Browse files Browse the repository at this point in the history
When 'authorization' header is present, there needs to be a space after the scheme, or nothing after
the scheme.
  • Loading branch information
jwalton committed May 16, 2018
1 parent c7186db commit a01be9b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ function defaultIsPresent(context: ExegesisPluginContext, info: AuthenticatorInf
answer = false;
} else if(info.scheme) {
let authorization = context.req.headers['authorization'];
const scheme = info.scheme.toLowerCase();
if(authorization === null || authorization === undefined) {
answer = false;
} else {
if(!Array.isArray(authorization)) {
authorization = [authorization];
}
answer = authorization.some(authHeader =>
authHeader.slice(0, info.scheme!.length).toLowerCase() === info.scheme!.toLowerCase()
);
answer = authorization.some(authHeader => {
const normalizedHeader = authHeader.toLowerCase();
return normalizedHeader === scheme ||
normalizedHeader.startsWith(`${scheme} `);
});
}
}

Expand Down

0 comments on commit a01be9b

Please sign in to comment.