mirror of
https://github.com/github/codeql-action.git
synced 2025-12-27 01:30:10 +08:00
37 lines
1001 B
JavaScript
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
|
|
};
|