This commit is contained in:
eric sciple 2020-01-24 12:20:19 -05:00
parent beb1329f9f
commit 2b95e76931
7736 changed files with 1874747 additions and 51184 deletions

View file

@ -1,23 +1,23 @@
module.exports = withAuthorizationPrefix
module.exports = withAuthorizationPrefix;
const atob = require('atob-lite')
const atob = require("atob-lite");
const REGEX_IS_BASIC_AUTH = /^[\w-]+:/
const REGEX_IS_BASIC_AUTH = /^[\w-]+:/;
function withAuthorizationPrefix (authorization) {
function withAuthorizationPrefix(authorization) {
if (/^(basic|bearer|token) /i.test(authorization)) {
return authorization
return authorization;
}
try {
if (REGEX_IS_BASIC_AUTH.test(atob(authorization))) {
return `basic ${authorization}`
return `basic ${authorization}`;
}
} catch (error) { }
} catch (error) {}
if (authorization.split(/\./).length === 3) {
return `bearer ${authorization}`
return `bearer ${authorization}`;
}
return `token ${authorization}`
return `token ${authorization}`;
}