mirror of
https://github.com/ASzc/change-string-case-action.git
synced 2024-11-24 02:03:50 +08:00
18 lines
565 B
JavaScript
18 lines
565 B
JavaScript
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,
|
|
tokenType
|
|
};
|
|
}
|
|
export {
|
|
auth
|
|
};
|