Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: appId argument can be set to Client ID string #606

Merged
merged 7 commits into from
May 9, 2024
6 changes: 4 additions & 2 deletions src/get-app-authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export async function getAppAuthentication({
appId,
privateKey,
timeDifference,
}: State & { timeDifference?: number }): Promise<AppAuthentication> {
}: State & {
timeDifference?: number;
}): Promise<AppAuthentication> {
try {
const appAuthentication = await githubAppJwt({
id: +appId,
id: appId,
privateKey,
now: timeDifference && Math.floor(Date.now() / 1000) + timeDifference,
});
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export type UTC_TIMESTAMP = string;
export type AppAuthentication = {
type: APP_TYPE;
token: JWT;
appId: number;
appId: number | string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a later date, maybe we could use template literal strings to better define the format

Suggested change
appId: number | string;
appId: number | `Iv1.${string}`;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this would imply a change in universal-github-app-jwt first. Do you want me to open an issue there first?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appId: number | Iv1.${string};

I wouldn't do that, because there is a chance that future Client IDs will start with lv2.... and I also think there are old apps that still have a client ID without the lv1 prefix

expiresAt: string;
};

Expand Down
42 changes: 42 additions & 0 deletions test/typescript-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// THIS CODE IS NOT EXECUTED. IT IS JUST FOR TYPECHECKING
// ************************************************************

import { getAppAuthentication } from "../src/get-app-authentication.js";
import { request } from "@octokit/request";
import { createAppAuth } from "../src/index.js";
import { State, StrategyOptions } from "../src/types.js";
import { getCache } from "../src/cache.js";
import { createOAuthAppAuth } from "@octokit/auth-oauth-app";
function isString(what: string) {}

export async function readmeExample() {
Expand Down Expand Up @@ -31,3 +36,40 @@ export async function issue282() {

isString(authentication.token);
}

// https://github.com/octokit/auth-app.js/issues/603
export async function issue603() {
createAppAuth({
appId: "1",
privateKey: "",
});

const options: StrategyOptions = {
appId: "1",
oscard0m marked this conversation as resolved.
Show resolved Hide resolved
privateKey: "",
};

const state: State = Object.assign(
{
request,
cache: getCache(),
},
options,
options.installationId
? { installationId: Number(options.installationId) }
: {},
{
log: {
warn: console.warn.bind(console),
},
oauthApp: createOAuthAppAuth({
clientType: "github-app",
clientId: options.clientId || "",
clientSecret: options.clientSecret || "",
request,
}),
},
);

getAppAuthentication(state);
}