Skip to content

Commit d5d5028

Browse files
authored
feat: options.id can be set to Client ID (#107)
1 parent 34ebd5c commit d5d5028

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ For a complete implementation of GitHub App authentication strategies, see [`@oc
107107
<code>options.id</code>
108108
</th>
109109
<th>
110-
<code>number</code>
110+
<code>number | string</code>
111111
</th>
112112
<td>
113-
<strong>Required</strong>. Find <strong>App ID</strong> on the app’s about page in settings.
113+
<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.
114114
</td>
115115
</tr>
116116
<tr>
@@ -163,7 +163,7 @@ For a complete implementation of GitHub App authentication strategies, see [`@oc
163163
<code>number</code>
164164
</th>
165165
<td>
166-
The GitHub App database ID passed in <code>options.id</code>.
166+
The GitHub App database ID or Client ID passed in <code>options.id</code>.
167167
</td>
168168
</tr>
169169
<tr>

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { getToken } from "./get-token";
22

33
import { Options, Result } from "./types";
44

5-
export async function githubAppJwt({
5+
export async function githubAppJwt<T extends number | string = number>({
66
id,
77
privateKey,
88
now = Math.floor(Date.now() / 1000),
9-
}: Options): Promise<Result> {
9+
}: Options<T>): Promise<Result<T>> {
1010
// When creating a JSON Web Token, it sets the "issued at time" (iat) to 30s
1111
// in the past as we have seen people running situations where the GitHub API
1212
// claimed the iat would be in future. It turned out the clocks on the

src/types.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
export type PrivateKey = string;
2-
export type AppId = number;
32
export type Expiration = number;
43
export type Token = string;
54

6-
export type Options = {
7-
id: AppId;
5+
export type Options<IdType extends number | string = number> = {
6+
id: IdType;
87
privateKey: PrivateKey;
98
now?: number;
109
};
1110

12-
export type Result = {
13-
appId: AppId;
11+
export type Result<IdType extends number | string = number> = {
12+
appId: IdType;
1413
expiration: Expiration;
1514
token: Token;
1615
};
1716

1817
export type Payload = {
1918
iat: number;
2019
exp: number;
21-
iss: number;
20+
iss: number | string;
2221
};
2322

2423
export type GetTokenOptions = {

test/node.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,14 @@ test("Include the time difference in the expiration and issued_at field", async
114114
expect(resultPayload.exp).toEqual(580);
115115
expect(resultPayload.iat).toEqual(-20);
116116
});
117+
118+
// New test for id set to Client ID
119+
test("id set to Client ID", async () => {
120+
const result = await githubAppJwt({
121+
id: "client_id_string",
122+
privateKey: PRIVATE_KEY_PKCS8,
123+
});
124+
125+
expect(typeof result.token).toEqual("string");
126+
expect(result.appId).toEqual("client_id_string");
127+
});

0 commit comments

Comments
 (0)