UNPKG

aws-delivlib

Version:

A fabulous library for defining continuous pipelines for building, testing and releasing code libraries.

32 lines (31 loc) 909 B
import { githubAppJwt } from "universal-github-app-jwt"; async function getAppAuthentication({ appId, privateKey, timeDifference }) { try { const appAuthentication = await githubAppJwt({ id: +appId, privateKey, now: timeDifference && Math.floor(Date.now() / 1e3) + timeDifference }); return { type: "app", token: appAuthentication.token, appId: appAuthentication.appId, expiresAt: new Date(appAuthentication.expiration * 1e3).toISOString() }; } catch (error) { if (privateKey === "-----BEGIN RSA PRIVATE KEY-----") { throw new Error( "The 'privateKey` option contains only the first line '-----BEGIN RSA PRIVATE KEY-----'. If you are setting it using a `.env` file, make sure it is set on a single line with newlines replaced by '\n'" ); } else { throw error; } } } export { getAppAuthentication };