universal-github-app-jwt
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -20,3 +20,4 @@ 'use strict'; | ||
id, | ||
privateKey | ||
privateKey, | ||
now = Math.floor(Date.now() / 1000) | ||
}) { | ||
@@ -27,7 +28,7 @@ // When creating a JSON Web Token, it sets the "issued at time" (iat) to 30s | ||
// different machine were not in sync. | ||
const now = Math.floor(Date.now() / 1000) - 30; | ||
const expiration = now + 60 * 10; // JWT expiration time (10 minute maximum) | ||
const nowWithSafetyMargin = now - 30; | ||
const expiration = nowWithSafetyMargin + 60 * 10; // JWT expiration time (10 minute maximum) | ||
const payload = { | ||
iat: now, | ||
iat: nowWithSafetyMargin, | ||
exp: expiration, | ||
@@ -34,0 +35,0 @@ iss: id |
import { getToken } from "./get-token"; | ||
export async function githubAppJwt({ id, privateKey }) { | ||
export async function githubAppJwt({ id, privateKey, now = Math.floor(Date.now() / 1000), }) { | ||
// When creating a JSON Web Token, it sets the "issued at time" (iat) to 30s | ||
@@ -7,6 +7,6 @@ // in the past as we have seen people running situations where the GitHub API | ||
// different machine were not in sync. | ||
const now = Math.floor(Date.now() / 1000) - 30; | ||
const expiration = now + 60 * 10; // JWT expiration time (10 minute maximum) | ||
const nowWithSafetyMargin = now - 30; | ||
const expiration = nowWithSafetyMargin + 60 * 10; // JWT expiration time (10 minute maximum) | ||
const payload = { | ||
iat: now, | ||
iat: nowWithSafetyMargin, | ||
exp: expiration, | ||
@@ -13,0 +13,0 @@ iss: id |
import { Options, Result } from "./types"; | ||
export declare function githubAppJwt({ id, privateKey }: Options): Promise<Result>; | ||
export declare function githubAppJwt({ id, privateKey, now, }: Options): Promise<Result>; |
@@ -8,3 +8,3 @@ export declare type PrivateKey = string; | ||
privateKey: PrivateKey; | ||
crypto?: Crypto; | ||
now?: number; | ||
}; | ||
@@ -11,0 +11,0 @@ export declare type Result = { |
@@ -1,2 +0,2 @@ | ||
function t(t,n,r,e,i,a,o){try{var u=t[a](o),c=u.value}catch(t){return void r(t)}u.done?n(c):Promise.resolve(c).then(e,i)}function n(n){return function(){var r=this,e=arguments;return new Promise((function(i,a){var o=n.apply(r,e);function u(n){t(o,i,a,u,c,"next",n)}function c(n){t(o,i,a,u,c,"throw",n)}u(void 0)}))}}function r(t){for(var n=new ArrayBuffer(t.length),r=new Uint8Array(n),e=0,i=t.length;e<i;e++)r[e]=t.charCodeAt(e);return n}function e(t){return t.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function i(t){return e(btoa(JSON.stringify(t)))}var a=function(){var t=n((function*(t){var{privateKey:n,payload:a}=t;if(/BEGIN RSA PRIVATE KEY/.test(n))throw new Error("[universal-github-app-jwt] Private Key is in PKCS#1 format, but only PKCS#8 is supported. See https://github.com/gr2m/universal-github-app-jwt#readme");var o,u={name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},c=(o=n.trim().split("\n").slice(1,-1).join(""),r(atob(o))),p=yield crypto.subtle.importKey("pkcs8",c,u,!1,["sign"]),f=function(t,n){return"".concat(i(t),".").concat(i(n))}({alg:"RS256",typ:"JWT"},a),l=r(f),s=function(t){for(var n="",r=new Uint8Array(t),i=r.byteLength,a=0;a<i;a++)n+=String.fromCharCode(r[a]);return e(btoa(n))}(yield crypto.subtle.sign(u.name,p,l));return"".concat(f,".").concat(s)}));return function(n){return t.apply(this,arguments)}}();function o(t){return u.apply(this,arguments)}function u(){return(u=n((function*(t){var{id:n,privateKey:r}=t,e=Math.floor(Date.now()/1e3)-30,i=e+600,o={iat:e,exp:i,iss:n};return{appId:n,expiration:i,token:yield a({privateKey:r,payload:o})}}))).apply(this,arguments)}export{o as githubAppJwt}; | ||
function t(t,n,r,e,i,a,o){try{var u=t[a](o),c=u.value}catch(t){return void r(t)}u.done?n(c):Promise.resolve(c).then(e,i)}function n(n){return function(){var r=this,e=arguments;return new Promise((function(i,a){var o=n.apply(r,e);function u(n){t(o,i,a,u,c,"next",n)}function c(n){t(o,i,a,u,c,"throw",n)}u(void 0)}))}}function r(t){for(var n=new ArrayBuffer(t.length),r=new Uint8Array(n),e=0,i=t.length;e<i;e++)r[e]=t.charCodeAt(e);return n}function e(t){return t.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function i(t){return e(btoa(JSON.stringify(t)))}var a=function(){var t=n((function*(t){var{privateKey:n,payload:a}=t;if(/BEGIN RSA PRIVATE KEY/.test(n))throw new Error("[universal-github-app-jwt] Private Key is in PKCS#1 format, but only PKCS#8 is supported. See https://github.com/gr2m/universal-github-app-jwt#readme");var o,u={name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},c=(o=n.trim().split("\n").slice(1,-1).join(""),r(atob(o))),p=yield crypto.subtle.importKey("pkcs8",c,u,!1,["sign"]),f=function(t,n){return"".concat(i(t),".").concat(i(n))}({alg:"RS256",typ:"JWT"},a),l=r(f),s=function(t){for(var n="",r=new Uint8Array(t),i=r.byteLength,a=0;a<i;a++)n+=String.fromCharCode(r[a]);return e(btoa(n))}(yield crypto.subtle.sign(u.name,p,l));return"".concat(f,".").concat(s)}));return function(n){return t.apply(this,arguments)}}();function o(t){return u.apply(this,arguments)}function u(){return(u=n((function*(t){var{id:n,privateKey:r,now:e=Math.floor(Date.now()/1e3)}=t,i=e-30,o=i+600,u={iat:i,exp:o,iss:n};return{appId:n,expiration:o,token:yield a({privateKey:r,payload:u})}}))).apply(this,arguments)}export{o as githubAppJwt}; | ||
//# sourceMappingURL=index.bundled.js.map |
@@ -59,3 +59,3 @@ function string2ArrayBuffer(str) { | ||
async function githubAppJwt({ id, privateKey }) { | ||
async function githubAppJwt({ id, privateKey, now = Math.floor(Date.now() / 1000), }) { | ||
// When creating a JSON Web Token, it sets the "issued at time" (iat) to 30s | ||
@@ -65,6 +65,6 @@ // in the past as we have seen people running situations where the GitHub API | ||
// different machine were not in sync. | ||
const now = Math.floor(Date.now() / 1000) - 30; | ||
const expiration = now + 60 * 10; // JWT expiration time (10 minute maximum) | ||
const nowWithSafetyMargin = now - 30; | ||
const expiration = nowWithSafetyMargin + 60 * 10; // JWT expiration time (10 minute maximum) | ||
const payload = { | ||
iat: now, | ||
iat: nowWithSafetyMargin, | ||
exp: expiration, | ||
@@ -71,0 +71,0 @@ iss: id |
{ | ||
"name": "universal-github-app-jwt", | ||
"description": "Calculate GitHub App bearer tokens for Node & modern browsers", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -38,3 +38,3 @@ "files": [ | ||
"lolex": "^6.0.0", | ||
"playwright": "^0.13.0", | ||
"playwright": "^1.0.1", | ||
"prettier": "^2.0.0", | ||
@@ -44,3 +44,3 @@ "rollup-plugin-json": "^4.0.0", | ||
"serve-handler": "^6.1.1", | ||
"ts-jest": "^25.1.0", | ||
"ts-jest": "^26.0.0", | ||
"typescript": "^3.6.2" | ||
@@ -47,0 +47,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
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
29905
247