setup-rust-action/node_modules/@octokit/rest/plugins/authentication/with-authorization-prefix.js
Héctor Ramón Jiménez 7f8c3a27a4 Track node_modules
2019-08-15 19:37:37 +02:00

24 lines
511 B
JavaScript

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