Get a repo-scoped GitHub Access Token quickly

Get a repo-scoped GitHub Access Token quickly

Today I need an access token for github so that I could commit show transcripts for Syntax via some automated scripts.

Has three options:

  • Personal access token
  • oAuth access token
  • Apps access token

The first two give full access to all your repos - public and private. Kinda scary.

So I went the apps route. An app can be scoped to a repo with very fine grain access controls. Most of my time was spent looking for URLs and asking for helpful packages on twitter.

Here is how to to do it quickly:

  1. Create a new Github App. Select the permissions this access token will need. In my case it was just "Read + Write Contents". I also selected "Only on this account" as I only needed the token for myself.
  2. Once created, it will prompt you to make a public key. Download this.
  3. There will be a button to "Install App", click that.
  4. Select which repos you want it to access. You can always change this at https://github.com/settings/installations - find your app and click "configure".
  5. Note the "Installation Id" - we will need this.
  6. Note the App ID. Again, find this at the above link.
  7. Make a new directory, npm init, and then npm install github-app-installation-token. This is handy package to do it all quickly.
  8. Make a new get-ya-token.js file like this:
const { getToken } = require('github-app-installation-token');

async function go() {
  const res = await getToken({
    appId: 'from-earlier',
    installationId: 'from-earlier',
    privateKey: `Paste the contents of your private key in here. Use backticks because it's multi-line`,
  });
  console.log(res); // your token will be here
}

go();
  1. Run it! node get-ya-token.js

That should spit out a token.

Hope it helps.

Find an issue with this post? Think you could clarify, update or add something?

All my posts are available to edit on Github. Any fix, little or small, is appreciated!

Edit on Github

Syntax Podcast

Hold on — I'm grabbin' the last one.

Listen Now →
Syntax Podcast

@wesbos Instant Grams

Beginner JavaScript

Beginner JavaScript

A fun, exercise heavy approach to learning Modern JavaScript from scratch. This is a course for absolute beginners or anyone looking to brush up on their fundamentals. Start here if you are new to JS or programming in general!

BeginnerJavaScript.com
I post videos on and code on

Wes Bos © 1999 — 2024

Terms × Privacy Policy