CLI tool for generating various kinds of GitHub authentication tokens
3.8K
A JavaScript package, GitHub Action, and CLI tool for generating various kinds of GitHub authentication tokens, from other kinds of authentication tokens.
tokenType in GitHub Actions, command for CLI, function prefix for JS library)
app for "GitHub App" type apps - JWTs used for interacting with app APIs onlyinstallation for "GitHub App" type apps - Generated tokens for interacting with most of the GitHub API - Generated from an app token, and scoped to organization/user/etcorgRunnerRegistration for registering a GitHub Actions Runner with an organizationrepoRunnerRegistration for registering a GitHub Actions Runner with a repositorydebug: turn on debug outputs (true/false, or CLI flag)authorization: authorization header mode outputs a valid Authorization header value (true/false, CLI flag, or function suffix for JS library)appId: GitHub app IDprivateKey: private key data for the GitHub app (not available on the CLI)privateKeyPath: path to the private key file for the GitHub appinstallationId: installation ID for the apporgName: organization name to act onrepoName: full name of the repository to act onpersonalAccessToken: personal access token to use for generationMost options are optional, and all functions will show an error if a full set of values aren't available. For example:
personalAccessTokenappId, and one of privateKey or privateKeyPathinstallationIdorgName (installations are searched for the org name)repoName (installations are searched for the org name)After adding your app, add the private key as a repo secret
- id: token
name: Generate authorization
uses: RickyCook/[email protected]
with:
tokenType: installation
authorization: true
appId: 'deadbeef'
privateKey: ${{ secrets.appPrivateKey }}
repoName: myorg/privaterepo
- name: Check token works
env:
AUTH: ${{ steps.token.outputs.token }}
run: curl -H "Authorization:$AUTH" https://api.github.com/repos/myorg/privaterepo
tokenType - what type of token to generate
app - create an app JWTinstallation - create an installation tokenorgRunnerRegistration - create a token to manage self-hosted runners on a reporepoRunnerRegistration - create a token to manage self-hosted runners on an orgdebug - turn on debug outputsauthorization - turn on "authorization" mode to return the value of an authorization header for curl/httpie/etcappId, privateKey, etc)token - the generated token or authorization header valueconst https = require('https');
const githubTokens = require('github-tokens-generator');
// App ID and private key are from your app settings
const appId = 'deadbeef';
const privateKeyPath = '/tmp/myapp.2021-10-04.private-key.pem';
const repoName = 'myorg/privaterepo';
(async () => {
https.get(
`https://api.github.com/repos/${repoName}`,
{
headers: {
// create...Authorization functions add Bearer/token as required
// if you just need the token, you can use create...Token functions
Authorization: await githubTokens.createInstallationAuthorization({
appId, privateKeyPath, repoName,
}),
'User-Agent': 'nodejs',
}
},
res => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', d => process.stdout.write(d));
},
);
})();
token="$(
node src/bin.js \
installation \
--authorization \
--appId deadbeef \
--privateKeyPath /tmp/myapp.2021-10-04.private-key.pem \
--repoName myorg/privaterepo
)"
curl -H "Authorization:$token" https://api.github.com/repos/myorg/privaterepo
token="$(
docker run --rm -v /tmp/myapp.2020-10-04.private-key.pem:/key.pem \
thatpanda/github-auth-generator:1.1.2 \
installation \
--authorization \
--appId deadbeef \
--privateKeyPath /key.pem \
--repoName myorg/privaterepo
)"
curl -H "Authorization:$token" https://api.github.com/repos/myorg/privaterepo
This token can be used according to the GitHub Actions self-hosted runner docs in place of the token generated by the web UI.
node src/bin.js repoRunnerRegistration \
--appId deadbeef \
--privateKeyPath /tmp/myapp.2021-10-04.private-key.pem \
--repoName myorg/privaterepo
This token can be used according to the GitHub Actions self-hosted runner docs in place of the token generated by the web UI.
node src/bin.js repoRunnerRegistration \
--personalAccessToken deadbeef \
--repoName myorg/privaterepo
Navigate to your organization's developer settings:
https://github.com/organizations/<yourorg>/settings/apps
OR
Navigate to your personal developer settings:
https://github.com/settings/apps
Create a "GitHub App" (not an OAuth App) using these settings:
The appId setting of this library/CLI corresponds to the App ID on the app's about page
To retrieve a private key, scroll down on the app's about page and under "Private keys", click "Generate a private key". The PEM file that's saved corresponds to the privateKeyPath of this library/CLI
To allow access to repositories/orgs, in the app settings click "Install App". You can select any organization that you're a member of to install the app into (or there might only be 1 if you selected "only this account" in the setup). Click install, and then install again. You might like to select only a limited set of repositories.
Now you can use the app ID and private key to perform operations on your repository!
Content type
Image
Digest
sha256:fe79e1347…
Size
48.3 MB
Last updated
over 2 years ago
docker pull thatpanda/github-auth-generator