universal-github-app-jwt
Advanced tools
Comparing version
@@ -29,3 +29,2 @@ 'use strict'; | ||
const expiration = nowWithSafetyMargin + 60 * 10; // JWT expiration time (10 minute maximum) | ||
const payload = { | ||
@@ -32,0 +31,0 @@ iat: nowWithSafetyMargin, |
@@ -1,3 +0,3 @@ | ||
import { getEncodedMessage, getDERfromPEM, string2ArrayBuffer, base64encode } from "./utils"; | ||
export const getToken = async ({ privateKey, payload }) => { | ||
import { getEncodedMessage, getDERfromPEM, string2ArrayBuffer, base64encode, } from "./utils"; | ||
export const getToken = async ({ privateKey, payload, }) => { | ||
// WebCrypto only supports PKCS#8, unfortunately | ||
@@ -9,3 +9,3 @@ if (/BEGIN RSA PRIVATE KEY/.test(privateKey)) { | ||
name: "RSASSA-PKCS1-v1_5", | ||
hash: { name: "SHA-256" } | ||
hash: { name: "SHA-256" }, | ||
}; | ||
@@ -12,0 +12,0 @@ const header = { alg: "RS256", typ: "JWT" }; |
import jsonwebtoken from "jsonwebtoken"; | ||
export async function getToken({ privateKey, payload }) { | ||
export async function getToken({ privateKey, payload, }) { | ||
return jsonwebtoken.sign(payload, privateKey, { | ||
algorithm: "RS256" | ||
algorithm: "RS256", | ||
}); | ||
} |
@@ -12,7 +12,7 @@ import { getToken } from "./get-token"; | ||
exp: expiration, | ||
iss: id | ||
iss: id, | ||
}; | ||
const token = await getToken({ | ||
privateKey, | ||
payload | ||
payload, | ||
}); | ||
@@ -22,4 +22,4 @@ return { | ||
expiration, | ||
token | ||
token, | ||
}; | ||
} |
@@ -31,6 +31,3 @@ export function string2ArrayBuffer(str) { | ||
function fromBase64(base64) { | ||
return base64 | ||
.replace(/=/g, "") | ||
.replace(/\+/g, "-") | ||
.replace(/\//g, "_"); | ||
return base64.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"); | ||
} | ||
@@ -37,0 +34,0 @@ function base64encodeJSON(obj) { |
@@ -1,2 +0,2 @@ | ||
import { GetTokenOptions } from "./types"; | ||
export declare const getToken: ({ privateKey, payload }: GetTokenOptions) => Promise<string>; | ||
import { GetTokenOptions, Token } from "./types"; | ||
export declare const getToken: ({ privateKey, payload, }: GetTokenOptions) => Promise<Token>; |
import { GetTokenOptions, Token } from "./types"; | ||
export declare function getToken({ privateKey, payload }: GetTokenOptions): Promise<Token>; | ||
export declare function getToken({ privateKey, payload, }: GetTokenOptions): Promise<Token>; |
@@ -1,6 +0,6 @@ | ||
export declare type PrivateKey = string; | ||
export declare type AppId = number; | ||
export declare type Expiration = number; | ||
export declare type Token = string; | ||
export declare type Options = { | ||
export type PrivateKey = string; | ||
export type AppId = number; | ||
export type Expiration = number; | ||
export type Token = string; | ||
export type Options = { | ||
id: AppId; | ||
@@ -10,3 +10,3 @@ privateKey: PrivateKey; | ||
}; | ||
export declare type Result = { | ||
export type Result = { | ||
appId: AppId; | ||
@@ -16,3 +16,3 @@ expiration: Expiration; | ||
}; | ||
export declare type Payload = { | ||
export type Payload = { | ||
iat: number; | ||
@@ -22,5 +22,5 @@ exp: number; | ||
}; | ||
export declare type GetTokenOptions = { | ||
export type GetTokenOptions = { | ||
privateKey: PrivateKey; | ||
payload: Payload; | ||
}; |
@@ -31,6 +31,3 @@ function string2ArrayBuffer(str) { | ||
function fromBase64(base64) { | ||
return base64 | ||
.replace(/=/g, "") | ||
.replace(/\+/g, "-") | ||
.replace(/\//g, "_"); | ||
return base64.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"); | ||
} | ||
@@ -41,3 +38,3 @@ function base64encodeJSON(obj) { | ||
const getToken = async ({ privateKey, payload }) => { | ||
const getToken = async ({ privateKey, payload, }) => { | ||
// WebCrypto only supports PKCS#8, unfortunately | ||
@@ -49,3 +46,3 @@ if (/BEGIN RSA PRIVATE KEY/.test(privateKey)) { | ||
name: "RSASSA-PKCS1-v1_5", | ||
hash: { name: "SHA-256" } | ||
hash: { name: "SHA-256" }, | ||
}; | ||
@@ -72,7 +69,7 @@ const header = { alg: "RS256", typ: "JWT" }; | ||
exp: expiration, | ||
iss: id | ||
iss: id, | ||
}; | ||
const token = await getToken({ | ||
privateKey, | ||
payload | ||
payload, | ||
}); | ||
@@ -82,3 +79,3 @@ return { | ||
expiration, | ||
token | ||
token, | ||
}; | ||
@@ -85,0 +82,0 @@ } |
{ | ||
"name": "universal-github-app-jwt", | ||
"description": "Calculate GitHub App bearer tokens for Node & modern browsers", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"license": "MIT", | ||
@@ -25,4 +25,4 @@ "files": [ | ||
"dependencies": { | ||
"@types/jsonwebtoken": "^8.3.3", | ||
"jsonwebtoken": "^8.5.1" | ||
"@types/jsonwebtoken": "^9.0.0", | ||
"jsonwebtoken": "^9.0.0" | ||
}, | ||
@@ -35,7 +35,6 @@ "devDependencies": { | ||
"@pika/plugin-ts-standard-pkg": "^0.9.1", | ||
"@types/jest": "^25.1.0", | ||
"@types/jest": "^26.0.0", | ||
"@types/lolex": "^5.1.0", | ||
"jest": "^25.1.0", | ||
"jest": "^26.0.0", | ||
"lolex": "^6.0.0", | ||
"playwright": "^1.0.1", | ||
"prettier": "^2.0.0", | ||
@@ -46,3 +45,3 @@ "rollup-plugin-json": "^4.0.0", | ||
"ts-jest": "^26.0.0", | ||
"typescript": "^3.6.2" | ||
"typescript": "^4.9.4" | ||
}, | ||
@@ -49,0 +48,0 @@ "source": "dist-src/index.js", |
@@ -71,3 +71,3 @@ # universal-github-app-jwt | ||
id: APP_ID, | ||
privateKey: PRIVATE_KEY | ||
privateKey: PRIVATE_KEY, | ||
}); | ||
@@ -82,4 +82,4 @@ })(); | ||
headers: { | ||
authorization: `bearer ${token}` | ||
} | ||
authorization: `bearer ${token}`, | ||
}, | ||
}); | ||
@@ -86,0 +86,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15
-6.25%29646
-0.87%242
-2.02%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated