diff --git a/README.md b/README.md index 78649d3..ff562cf 100644 --- a/README.md +++ b/README.md @@ -87,10 +87,10 @@ For a complete implementation of GitHub App authentication strategies, see [`@oc options.id - number + number | string - Required. Find App ID on the app’s about page in settings. + Required. The GitHub App's ID or Client ID. For github.com and GHES 3.14+, it is recommended to use the Client ID. @@ -154,7 +154,7 @@ For a complete implementation of GitHub App authentication strategies, see [`@oc number - The GitHub App database ID passed in options.id. + The GitHub App database ID or Client ID passed in options.id. diff --git a/index.d.ts b/index.d.ts index dba0a82..6f67a05 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,13 +1,13 @@ -export type Options = { - id: number; +export type Options = { + id: IdType; privateKey: string; now?: number; }; -export type Result = { - appId: number; +export type Result = { + appId: IdType extends string ? string : number; expiration: number; token: string; }; -export default function githubAppJwt(options: Options): Promise; +export default function githubAppJwt(options: Options): Promise>; diff --git a/index.test-d.ts b/index.test-d.ts index 4107655..f500ad5 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -11,3 +11,15 @@ export async function test() { expectType(result.expiration); expectType(result.token); } + +// Test case to verify `id` can be set to a string +export async function testWithStringId() { + const resultWithStringId = await githubAppJwt({ + id: "client_id_string", + privateKey: "", + }); + + expectType(resultWithStringId.appId); + expectType(resultWithStringId.expiration); + expectType(resultWithStringId.token); +} diff --git a/internals.d.ts b/internals.d.ts index 586ab39..a7c9301 100644 --- a/internals.d.ts +++ b/internals.d.ts @@ -1,7 +1,7 @@ export type Payload = { iat: number; exp: number; - iss: number; + iss: number | string; }; export type Header = { alg: "RS256"; typ: "JWT" }; diff --git a/test/node.test.js b/test/node.test.js index 18a5d34..f47a01f 100644 --- a/test/node.test.js +++ b/test/node.test.js @@ -177,3 +177,16 @@ test("Replace escaped line breaks with actual linebreaks", async (t) => { token: BEARER, }); }); + +// New test for id set to Client ID +test("id set to Client ID", async (t) => { + MockDate.set(0); + + const result = await githubAppJwt({ + id: "client_id_string", + privateKey: PRIVATE_KEY_PKCS8, + }); + + t.is(typeof result.token, "string"); + t.is(result.appId, "client_id_string"); +});