Skip to content

Commit 8905248

Browse files
authored
Use octokit REST API for creating installation access token (#47)
1 parent 9edcc8a commit 8905248

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/fetch-installation-token.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export const fetchInstallationToken = async ({
2929
}),
3030
});
3131

32+
const authApp = await app({ type: "app" });
33+
const octokit = getOctokit(authApp.token);
3234
if (installationId === undefined) {
33-
const authApp = await app({ type: "app" });
34-
const octokit = getOctokit(authApp.token);
3535
try {
3636
({
3737
data: { id: installationId },
@@ -44,10 +44,16 @@ export const fetchInstallationToken = async ({
4444
}
4545
}
4646

47-
const installation = await app({
48-
installationId,
49-
permissions,
50-
type: "installation",
51-
});
52-
return installation.token;
47+
try {
48+
const { data: installation } =
49+
await octokit.rest.apps.createInstallationAccessToken({
50+
installation_id: installationId,
51+
permissions,
52+
});
53+
return installation?.token;
54+
} catch (error: unknown) {
55+
throw new Error("Could not create installation access token.", {
56+
cause: ensureError(error),
57+
});
58+
}
5359
};

0 commit comments

Comments
 (0)