@octokit/auth-token
Advanced tools
Comparing version 2.4.5 to 2.5.0
@@ -5,4 +5,10 @@ 'use strict'; | ||
const REGEX_IS_INSTALLATION_LEGACY = /^v1\./; | ||
const REGEX_IS_INSTALLATION = /^ghs_/; | ||
const REGEX_IS_USER_TO_SERVER = /^ghu_/; | ||
async function auth(token) { | ||
const tokenType = token.split(/\./).length === 3 ? "app" : /^v\d+\./.test(token) ? "installation" : "oauth"; | ||
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 { | ||
@@ -9,0 +15,0 @@ type: "token", |
@@ -0,12 +1,21 @@ | ||
const REGEX_IS_INSTALLATION_LEGACY = /^v1\./; | ||
const REGEX_IS_INSTALLATION = /^ghs_/; | ||
const REGEX_IS_USER_TO_SERVER = /^ghu_/; | ||
export async function auth(token) { | ||
const tokenType = token.split(/\./).length === 3 | ||
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" | ||
: /^v\d+\./.test(token) | ||
: isInstallation | ||
? "installation" | ||
: "oauth"; | ||
: isUserToServer | ||
? "user-to-server" | ||
: "oauth"; | ||
return { | ||
type: "token", | ||
token: token, | ||
tokenType | ||
tokenType, | ||
}; | ||
} |
@@ -12,4 +12,4 @@ import { auth } from "./auth"; | ||
return Object.assign(auth.bind(null, token), { | ||
hook: hook.bind(null, token) | ||
hook: hook.bind(null, token), | ||
}); | ||
}; |
@@ -28,2 +28,7 @@ import * as OctokitTypes from "@octokit/types"; | ||
}; | ||
export declare type Authentication = OAuthTokenAuthentication | InstallationTokenAuthentication | AppAuthentication; | ||
export declare type UserToServerAuthentication = { | ||
type: "token"; | ||
tokenType: "user-to-server"; | ||
token: Token; | ||
}; | ||
export declare type Authentication = OAuthTokenAuthentication | InstallationTokenAuthentication | AppAuthentication | UserToServerAuthentication; |
@@ -0,11 +1,20 @@ | ||
const REGEX_IS_INSTALLATION_LEGACY = /^v1\./; | ||
const REGEX_IS_INSTALLATION = /^ghs_/; | ||
const REGEX_IS_USER_TO_SERVER = /^ghu_/; | ||
async function auth(token) { | ||
const tokenType = token.split(/\./).length === 3 | ||
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" | ||
: /^v\d+\./.test(token) | ||
: isInstallation | ||
? "installation" | ||
: "oauth"; | ||
: isUserToServer | ||
? "user-to-server" | ||
: "oauth"; | ||
return { | ||
type: "token", | ||
token: token, | ||
tokenType | ||
tokenType, | ||
}; | ||
@@ -41,3 +50,3 @@ } | ||
return Object.assign(auth.bind(null, token), { | ||
hook: hook.bind(null, token) | ||
hook: hook.bind(null, token), | ||
}); | ||
@@ -44,0 +53,0 @@ }; |
{ | ||
"name": "@octokit/auth-token", | ||
"description": "GitHub API token authentication for browsers and Node.js", | ||
"version": "2.4.5", | ||
"version": "2.5.0", | ||
"license": "MIT", | ||
@@ -18,7 +18,3 @@ "files": [ | ||
], | ||
"homepage": "https://github.com/octokit/auth-token.js#readme", | ||
"bugs": { | ||
"url": "https://github.com/octokit/auth-token.js/issues" | ||
}, | ||
"repository": "https://github.com/octokit/auth-token.js", | ||
"repository": "github:octokit/auth-token.js", | ||
"dependencies": { | ||
@@ -35,7 +31,8 @@ "@octokit/types": "^6.0.3" | ||
"@types/fetch-mock": "^7.3.1", | ||
"@types/jest": "^26.0.0", | ||
"@types/jest": "^27.0.0", | ||
"fetch-mock": "^9.0.0", | ||
"jest": "^26.0.0", | ||
"jest": "^27.0.0", | ||
"prettier": "2.4.1", | ||
"semantic-release": "^17.0.0", | ||
"ts-jest": "^26.0.0", | ||
"ts-jest": "^27.0.0-next.12", | ||
"typescript": "^4.0.0" | ||
@@ -42,0 +39,0 @@ }, |
@@ -61,7 +61,7 @@ # auth-token.js | ||
```js | ||
const auth = createTokenAuth("1234567890abcdef1234567890abcdef12345678"); | ||
const auth = createTokenAuth("ghp_PersonalAccessToken01245678900000000"); | ||
const authentication = await auth(); | ||
// { | ||
// type: 'token', | ||
// token: '1234567890abcdef1234567890abcdef12345678', | ||
// token: 'ghp_PersonalAccessToken01245678900000000', | ||
// tokenType: 'oauth' | ||
@@ -77,4 +77,5 @@ // } | ||
- [OAuth access token](https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/) | ||
- Installation access token ([GitHub App Installation](https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-an-installation)) | ||
- [GITHUB_TOKEN provided to GitHub Actions](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables) | ||
- Installation access token ([server-to-server](https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-an-installation)) | ||
- User authentication for installation ([user-to-server](https://docs.github.com/en/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps)) | ||
@@ -85,6 +86,24 @@ Examples | ||
// Personal access token or OAuth access token | ||
createTokenAuth("1234567890abcdef1234567890abcdef12345678"); | ||
createTokenAuth("ghp_PersonalAccessToken01245678900000000"); | ||
// { | ||
// type: 'token', | ||
// token: 'ghp_PersonalAccessToken01245678900000000', | ||
// tokenType: 'oauth' | ||
// } | ||
// Installation access token or GitHub Action token | ||
createTokenAuth("v1.d3d433526f780fbcc3129004e2731b3904ad0b86"); | ||
createTokenAuth("ghs_InstallallationOrActionToken00000000"); | ||
// { | ||
// type: 'token', | ||
// token: 'ghs_InstallallationOrActionToken00000000', | ||
// tokenType: 'installation' | ||
// } | ||
// Installation access token or GitHub Action token | ||
createTokenAuth("ghu_InstallationUserToServer000000000000"); | ||
// { | ||
// type: 'token', | ||
// token: 'ghu_InstallationUserToServer000000000000', | ||
// tokenType: 'user-to-server' | ||
// } | ||
``` | ||
@@ -143,3 +162,3 @@ | ||
<td> | ||
Can be either <code>"oauth"</code> for personal access tokens and OAuth tokens, or <code>"installation"</code> for installation access tokens (includes <code>GITHUB_TOKEN</code> provided to GitHub Actions) | ||
Can be either <code>"oauth"</code> for personal access tokens and OAuth tokens, <code>"installation"</code> for installation access tokens (includes <code>GITHUB_TOKEN</code> provided to GitHub Actions), <code>"app"</code> for a GitHub App JSON Web Token, or <code>"user-to-server"</code> for a user authentication token through an app installation. | ||
</td> | ||
@@ -188,3 +207,3 @@ </tr> | ||
```js | ||
const TOKEN = "1234567890abcdef1234567890abcdef12345678"; | ||
const TOKEN = "ghp_PersonalAccessToken01245678900000000"; | ||
@@ -211,3 +230,3 @@ const auth = createTokenAuth(TOKEN); | ||
```js | ||
const TOKEN = "1234567890abcdef1234567890abcdef12345678"; | ||
const TOKEN = "ghp_PersonalAccessToken01245678900000000"; | ||
@@ -236,3 +255,3 @@ const auth = createTokenAuth(TOKEN); | ||
```js | ||
const TOKEN = "1234567890abcdef1234567890abcdef12345678"; | ||
const TOKEN = "ghp_PersonalAccessToken01245678900000000"; | ||
@@ -263,3 +282,3 @@ const auth = createTokenAuth(TOKEN); | ||
```js | ||
const TOKEN = "1234567890abcdef1234567890abcdef12345678"; | ||
const TOKEN = "ghp_PersonalAccessToken01245678900000000"; | ||
@@ -266,0 +285,0 @@ const auth = createTokenAuth(TOKEN); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
25794
200
291
14
2
1