Files
labeler/node_modules/@octokit/rest/plugins/authentication/with-authorization-prefix.js
T

24 lines
516 B
JavaScript
Raw Normal View History

module.exports = withAuthorizationPrefix;
2019-08-08 10:10:17 -04:00
const atob = require("atob-lite");
2019-08-08 10:10:17 -04:00
const REGEX_IS_BASIC_AUTH = /^[\w-]+:/;
2019-08-08 10:10:17 -04:00
function withAuthorizationPrefix(authorization) {
2019-08-08 10:10:17 -04:00
if (/^(basic|bearer|token) /i.test(authorization)) {
return authorization;
2019-08-08 10:10:17 -04:00
}
try {
if (REGEX_IS_BASIC_AUTH.test(atob(authorization))) {
return `basic ${authorization}`;
2019-08-08 10:10:17 -04:00
}
} catch (error) {}
2019-08-08 10:10:17 -04:00
if (authorization.split(/\./).length === 3) {
return `bearer ${authorization}`;
2019-08-08 10:10:17 -04:00
}
return `token ${authorization}`;
2019-08-08 10:10:17 -04:00
}