Files
codeql-action/node_modules/@octokit/auth-app/dist-src/get-app-authentication.js
2025-02-19 11:13:12 -08:00

37 lines
1001 B
JavaScript

import githubAppJwt from "universal-github-app-jwt";
async function getAppAuthentication({
appId,
privateKey,
timeDifference
}) {
try {
const authOptions = {
id: appId,
privateKey
};
if (timeDifference) {
Object.assign(authOptions, {
now: Math.floor(Date.now() / 1e3) + timeDifference
});
}
const appAuthentication = await githubAppJwt(authOptions);
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
};