mirror of
https://github.com/ASzc/change-string-case-action.git
synced 2024-11-24 02:13:51 +08:00
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
// pkg/dist-src/auth.js
|
|
var REGEX_IS_INSTALLATION_LEGACY = /^v1\./;
|
|
var REGEX_IS_INSTALLATION = /^ghs_/;
|
|
var 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,
|
|
tokenType
|
|
};
|
|
}
|
|
|
|
// pkg/dist-src/with-authorization-prefix.js
|
|
function withAuthorizationPrefix(token) {
|
|
if (token.split(/\./).length === 3) {
|
|
return `bearer ${token}`;
|
|
}
|
|
return `token ${token}`;
|
|
}
|
|
|
|
// pkg/dist-src/hook.js
|
|
async function hook(token, request, route, parameters) {
|
|
const endpoint = request.endpoint.merge(
|
|
route,
|
|
parameters
|
|
);
|
|
endpoint.headers.authorization = withAuthorizationPrefix(token);
|
|
return request(endpoint);
|
|
}
|
|
|
|
// pkg/dist-src/index.js
|
|
var createTokenAuth = function createTokenAuth2(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)
|
|
});
|
|
};
|
|
export {
|
|
createTokenAuth
|
|
};
|