@octokit/auth-token
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -6,3 +6,3 @@ 'use strict'; | ||
async function auth(token) { | ||
const tokenType = /^v\d+\./.test(token) ? "installation" : "oauth"; | ||
const tokenType = token.split(/\./).length === 3 ? "app" : /^v\d+\./.test(token) ? "installation" : "oauth"; | ||
return { | ||
@@ -15,9 +15,22 @@ type: "token", | ||
/** | ||
* 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 = `token ${token}`; | ||
endpoint.headers.authorization = withAuthorizationPrefix(token); | ||
return request(endpoint); | ||
} | ||
function createTokenAuth(token) { | ||
const createTokenAuth = function createTokenAuth(token) { | ||
if (!token) { | ||
@@ -31,8 +44,9 @@ throw new Error("[@octokit/auth-token] No token passed to createTokenAuth"); | ||
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 |
export async function auth(token) { | ||
const tokenType = /^v\d+\./.test(token) ? "installation" : "oauth"; | ||
const tokenType = token.split(/\./).length === 3 | ||
? "app" | ||
: /^v\d+\./.test(token) | ||
? "installation" | ||
: "oauth"; | ||
return { | ||
@@ -4,0 +8,0 @@ type: "token", |
@@ -0,5 +1,6 @@ | ||
import { withAuthorizationPrefix } from "./with-authorization-prefix"; | ||
export async function hook(token, request, route, parameters) { | ||
const endpoint = request.endpoint.merge(route, parameters); | ||
endpoint.headers.authorization = `token ${token}`; | ||
endpoint.headers.authorization = withAuthorizationPrefix(token); | ||
return request(endpoint); | ||
} |
import { auth } from "./auth"; | ||
import { hook } from "./hook"; | ||
export function createTokenAuth(token) { | ||
export const createTokenAuth = function createTokenAuth(token) { | ||
if (!token) { | ||
@@ -10,5 +10,6 @@ throw new Error("[@octokit/auth-token] No token passed to createTokenAuth"); | ||
} | ||
token = token.replace(/^(token|bearer) +/i, ""); | ||
return Object.assign(auth.bind(null, token), { | ||
hook: hook.bind(null, token) | ||
}); | ||
} | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { AuthInterface, Token } from "./types"; | ||
export declare function createTokenAuth(token: Token): AuthInterface; | ||
import { StrategyInterface } from "./types"; | ||
export declare const createTokenAuth: StrategyInterface; |
import * as OctokitTypes from "@octokit/types"; | ||
export declare type AnyResponse = OctokitTypes.OctokitResponse<any>; | ||
export declare type AuthInterface = OctokitTypes.AuthInterface; | ||
export declare type StrategyInterface = OctokitTypes.StrategyInterface<[Token], [], Authentication>; | ||
export declare type EndpointDefaults = OctokitTypes.EndpointDefaults; | ||
@@ -20,2 +20,7 @@ export declare type EndpointOptions = OctokitTypes.EndpointOptions; | ||
}; | ||
export declare type Authentication = OAuthTokenAuthentication | InstallationTokenAuthentication; | ||
export declare type AppAuthentication = { | ||
type: "token"; | ||
tokenType: "app"; | ||
token: Token; | ||
}; | ||
export declare type Authentication = OAuthTokenAuthentication | InstallationTokenAuthentication | AppAuthentication; |
async function auth(token) { | ||
const tokenType = /^v\d+\./.test(token) ? "installation" : "oauth"; | ||
const tokenType = token.split(/\./).length === 3 | ||
? "app" | ||
: /^v\d+\./.test(token) | ||
? "installation" | ||
: "oauth"; | ||
return { | ||
@@ -10,9 +14,21 @@ type: "token", | ||
/** | ||
* 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 = `token ${token}`; | ||
endpoint.headers.authorization = withAuthorizationPrefix(token); | ||
return request(endpoint); | ||
} | ||
function createTokenAuth(token) { | ||
const createTokenAuth = function createTokenAuth(token) { | ||
if (!token) { | ||
@@ -24,8 +40,9 @@ throw new Error("[@octokit/auth-token] No token passed to createTokenAuth"); | ||
} | ||
token = token.replace(/^(token|bearer) +/i, ""); | ||
return Object.assign(auth.bind(null, token), { | ||
hook: hook.bind(null, token) | ||
}); | ||
} | ||
}; | ||
export { createTokenAuth }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@octokit/auth-token", | ||
"description": "GitHub API token authentication for browsers and Node.js", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"license": "MIT", | ||
@@ -24,3 +24,3 @@ "files": [ | ||
"dependencies": { | ||
"@octokit/types": "^1.1.0" | ||
"@octokit/types": "^2.0.0" | ||
}, | ||
@@ -47,3 +47,3 @@ "devDependencies": { | ||
"main": "dist-node/index.js", | ||
"deno": "dist-web/index.js" | ||
"module": "dist-web/index.js" | ||
} |
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
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
21038
17
162
+ Added@octokit/types@2.16.2(transitive)
+ Added@types/node@22.9.0(transitive)
+ Addedundici-types@6.19.8(transitive)
- Removed@octokit/types@1.1.0(transitive)
- Removed@types/node@12.20.55(transitive)
Updated@octokit/types@^2.0.0