Register a GitHub App using the manifest flow
register-github-app.mov
importregisterGitHubAppfrom"register-github-app";constappCredentials=awaitregisterGitHubApp();console.log(appCredentials);importfsfrom"node:fs/promises";importcryptofrom"node:crypto";importregisterGitHubAppfrom"register-github-app";// register app and retrieve credentialsconstappCredentials=awaitregisterGitHubApp({// name of your appname: "my-github-app",// Homepage of your app, e.g. your app's repository or your org/user accounturl: "https://github.com/monatheoctocat/monas-github-app",// object of permissions for new installationsdefault_permissions: {issues: "write",},// List of events for new installationsevedefault_events: ["issues"],});// convert private key to pkcs8 format (recommended for better cross plattform support)constprivateKeyPKCS8=String(crypto.createPrivateKey(appCredentials.pem).export({type: "pkcs8",format: "pem",}),);constsingleLinePrivateKey=privateKeyPKCS8.trim().replace(/\n/g,"\\n");// write credentials into `.env` fileawaitfs.writeFile(".env",`GITHUB_APP_ID=${appCredentials.id}GITHUB_APP_PRIVATE_KEY="${singleLinePrivateKey}"GITHUB_APP_WEBHOOK_SECRET=${appCredentials.webhook_secret}GITHUB_APP_CLIENT_ID=${appCredentials.client_id}GITHUB_APP_SECRET=${appCredentials.client_secret}`,);importregisterGitHubAppfrom"register-github-app";// register app and retrieve credentialsconstappCredentials=awaitregisterGitHubApp({org: "my-organization-login",// name of your appname: "my-github-app",// object of permissions for new installationsdefault_permissions: {issues: "write",},// List of events for new installationsevedefault_events: ["issues"],});- https://github.com/gr2m/register-github - CLI to register a GitHub API using the manifest flow
Registering a GitHub App using the manifest flow is an alternative to manually register a GitHub App on a user account or an organization. Here is what the register-github-app does
- Starts a server on a random available port.
- When opened in browser, it generates an HTML form with an input named
manifestwhich value is set to a JSON string with the app manifest settings, and submits the form to github.com - On github.com, the user will be prompted to sign in or enter sudo mode.
- Once authenticated, the user has to confirm the GitHub App name. It must be globally unique.
- Once confirmed, the browser redirects to server started in the first step with a one-time code
- The app credentials are retrieved using the one-time code, the server is stopped, and the credentials are returned