GPR authentication support

This commit is contained in:
Alex Mullans authored and Alex Mullans committed 2019-10-03 16:35:25 -07:00
1 parent 6c0e2a2a6b
commit 6bd4969ec6
518 files changed
+95599 -2875

No files matched your search

@@ -0,0 +1,23 @@
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}`
}