Gets an auth token for a repo via a GitHub app installation
In order to simply credential management @electron/github-app-auth contains
a CLI tool to generate a "credential bundle" that contains the requisite
information to generate tokens. You need both a private key for your
application and the application ID.
- You can find your app's ID on the settings page for your GitHub App.
- To download your app's private key, see Managing private keys for GitHub Apps.
npx @electron/github-app-auth --cert=my-private.key.pem --app-id=12345This command will output a base64 encoded blob which you should store in your
services secret storage (normally accessed via an environment variable). Below
we will use MY_GITHUB_APP_CREDS as the environment variable.
import{appCredentialsFromString,getAuthOptionsForRepo}from'@electron/github-app-auth';import{Octokit}from'@octokit/rest';constcreds=appCredentialsFromString(process.env.MY_GITHUB_APP_CREDS);constauthOpts=awaitgetAuthOptionsForRepo({owner: 'electron',name: 'electron'},creds)constocto=newOctokit({
...authOpts,});// octo is now a valid octokit instanceimport{appCredentialsFromString,getTokenForRepo}from'@electron/github-app-auth';import{Octokit}from'@octokit/rest';constcreds=appCredentialsFromString(process.env.MY_GITHUB_APP_CREDS);consttoken=awaitgetTokenForRepo({owner: 'electron',name: 'electron'},creds)// token is now a valid github auth tokengh_token=$(npx @electron/github-app-auth --creds=$MY_GITHUB_APP_CREDS --owner=electron --repo=electron)