Mint a short-lived App JWT (valid ~9 min, iat backdated for clock skew).
(creds: GithubAppCredentials)
| 133 | |
| 134 | /** Mint a short-lived App JWT (valid ~9 min, iat backdated for clock skew). */ |
| 135 | async function mintAppJwt(creds: GithubAppCredentials): Promise<string> { |
| 136 | const key = await importSigningKey(creds.privateKey); |
| 137 | const nowSec = Math.floor(Date.now() / 1000); |
| 138 | const header = { alg: "RS256", typ: "JWT" }; |
| 139 | const payload = { iat: nowSec - 60, exp: nowSec + 540, iss: creds.appId }; |
| 140 | const signingInput = `${b64urlFromString(JSON.stringify(header))}.${b64urlFromString( |
| 141 | JSON.stringify(payload), |
| 142 | )}`; |
| 143 | const sig = await crypto.subtle.sign( |
| 144 | "RSASSA-PKCS1-v1_5", |
| 145 | key, |
| 146 | new TextEncoder().encode(signingInput), |
| 147 | ); |
| 148 | return `${signingInput}.${b64urlFromBytes(new Uint8Array(sig))}`; |
| 149 | } |
| 150 | |
| 151 | async function appJsonGet<T>(path: string, jwt: string): Promise<T> { |
| 152 | const res = await fetch(`${GITHUB_API}${path}`, { |
no test coverage detected