Skip to content

Commit dc462fa

Browse files
authored
feat: options.id can be set to Client ID (#98)
1 parent f7384cd commit dc462fa

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ For a complete implementation of GitHub App authentication strategies, see [`@oc
8787
<code>options.id</code>
8888
</th>
8989
<th>
90-
<code>number</code>
90+
<code>number | string</code>
9191
</th>
9292
<td>
93-
<strong>Required</strong>. Find <strong>App ID</strong> on the app’s about page in settings.
93+
<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.
9494
</td>
9595
</tr>
9696
<tr>
@@ -154,7 +154,7 @@ For a complete implementation of GitHub App authentication strategies, see [`@oc
154154
<code>number</code>
155155
</th>
156156
<td>
157-
The GitHub App database ID passed in <code>options.id</code>.
157+
The GitHub App database ID or Client ID passed in <code>options.id</code>.
158158
</td>
159159
</tr>
160160
<tr>

index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
export type Options = {
2-
id: number;
1+
export type Options<IdType extends number | string = number> = {
2+
id: IdType;
33
privateKey: string;
44
now?: number;
55
};
66

7-
export type Result = {
8-
appId: number;
7+
export type Result<IdType extends number | string = number> = {
8+
appId: IdType extends string ? string : number;
99
expiration: number;
1010
token: string;
1111
};
1212

13-
export default function githubAppJwt(options: Options): Promise<Result>;
13+
export default function githubAppJwt<T extends number | string = number>(options: Options<T>): Promise<Result<T>>;

index.test-d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ export async function test() {
1111
expectType<number>(result.expiration);
1212
expectType<string>(result.token);
1313
}
14+
15+
// Test case to verify `id` can be set to a string
16+
export async function testWithStringId() {
17+
const resultWithStringId = await githubAppJwt({
18+
id: "client_id_string",
19+
privateKey: "",
20+
});
21+
22+
expectType<string>(resultWithStringId.appId);
23+
expectType<number>(resultWithStringId.expiration);
24+
expectType<string>(resultWithStringId.token);
25+
}

internals.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type Payload = {
22
iat: number;
33
exp: number;
4-
iss: number;
4+
iss: number | string;
55
};
66

77
export type Header = { alg: "RS256"; typ: "JWT" };

test/node.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,16 @@ test("Replace escaped line breaks with actual linebreaks", async (t) => {
177177
token: BEARER,
178178
});
179179
});
180+
181+
// New test for id set to Client ID
182+
test("id set to Client ID", async (t) => {
183+
MockDate.set(0);
184+
185+
const result = await githubAppJwt({
186+
id: "client_id_string",
187+
privateKey: PRIVATE_KEY_PKCS8,
188+
});
189+
190+
t.is(typeof result.token, "string");
191+
t.is(result.appId, "client_id_string");
192+
});

0 commit comments

Comments
 (0)