Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ For a complete implementation of GitHub App authentication strategies, see [`@oc
<code>options.id</code>
</th>
<th>
<code>number</code>
<code>number | string</code>
</th>
<td>
<strong>Required</strong>. Find <strong>App ID</strong> on the app’s about page in settings.
<strong>Required</strong>. The GitHub App's ID or Client ID. For <code>github.com</code> and GHES 3.14+, it is recommended to use the Client ID.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -154,7 +154,7 @@ For a complete implementation of GitHub App authentication strategies, see [`@oc
<code>number</code>
</th>
<td>
The GitHub App database ID passed in <code>options.id</code>.
The GitHub App database ID or Client ID passed in <code>options.id</code>.
</td>
</tr>
<tr>
Expand Down
10 changes: 5 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export type Options = {
id: number;
export type Options<IdType extends number | string = number> = {
id: IdType;
privateKey: string;
now?: number;
};

export type Result = {
appId: number;
export type Result<IdType extends number | string = number> = {
appId: IdType extends string ? string : number;
expiration: number;
token: string;
};

export default function githubAppJwt(options: Options): Promise<Result>;
export default function githubAppJwt<T extends number | string = number>(options: Options<T>): Promise<Result<T>>;
12 changes: 12 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ export async function test() {
expectType<number>(result.expiration);
expectType<string>(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<string>(resultWithStringId.appId);
expectType<number>(resultWithStringId.expiration);
expectType<string>(resultWithStringId.token);
}
2 changes: 1 addition & 1 deletion internals.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type Payload = {
iat: number;
exp: number;
iss: number;
iss: number | string;
};

export type Header = { alg: "RS256"; typ: "JWT" };
Expand Down
13 changes: 13 additions & 0 deletions test/node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});