Permalink
Cannot retrieve contributors at this time
55 lines (46 sloc)
1.58 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/@octokit/auth-token/dist-node/index.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
Object.defineProperty(exports, '__esModule', { value: true }); | |
const REGEX_IS_INSTALLATION_LEGACY = /^v1\./; | |
const REGEX_IS_INSTALLATION = /^ghs_/; | |
const REGEX_IS_USER_TO_SERVER = /^ghu_/; | |
async function auth(token) { | |
const isApp = token.split(/\./).length === 3; | |
const isInstallation = REGEX_IS_INSTALLATION_LEGACY.test(token) || REGEX_IS_INSTALLATION.test(token); | |
const isUserToServer = REGEX_IS_USER_TO_SERVER.test(token); | |
const tokenType = isApp ? "app" : isInstallation ? "installation" : isUserToServer ? "user-to-server" : "oauth"; | |
return { | |
type: "token", | |
token: token, | |
tokenType | |
}; | |
} | |
/** | |
* Prefix token for usage in the Authorization header | |
* | |
* @param token OAuth token or JSON Web Token | |
*/ | |
function withAuthorizationPrefix(token) { | |
if (token.split(/\./).length === 3) { | |
return `bearer ${token}`; | |
} | |
return `token ${token}`; | |
} | |
async function hook(token, request, route, parameters) { | |
const endpoint = request.endpoint.merge(route, parameters); | |
endpoint.headers.authorization = withAuthorizationPrefix(token); | |
return request(endpoint); | |
} | |
const createTokenAuth = function createTokenAuth(token) { | |
if (!token) { | |
throw new Error("[@octokit/auth-token] No token passed to createTokenAuth"); | |
} | |
if (typeof token !== "string") { | |
throw new Error("[@octokit/auth-token] Token passed to createTokenAuth is not a string"); | |
} | |
token = token.replace(/^(token|bearer) +/i, ""); | |
return Object.assign(auth.bind(null, token), { | |
hook: hook.bind(null, token) | |
}); | |
}; | |
exports.createTokenAuth = createTokenAuth; | |
//# sourceMappingURL=index.js.map |