Given a JWT, how do you create an octokit client from it? Using NodeJS

339 views Asked by At

Given a JWT, how do you create an octokit client from it? Using NodeJS.

1

There are 1 answers

0
Johnny5 On

Solved it. https://github.com/octokit/auth-app.js

You don't actually use a JWT, you can use createAppAuth instead. If you need the token, it will be auth.token.

import { Octokit } from '@octokit/core';
import { createAppAuth } from '@octokit/auth-app';

async function getClient() {
    const authCreator = createAppAuth({
        appId: 123456,
        privateKey: "-----BEGIN RSA PRIVATE KEY-----\nBigUglyString\n-----END RSA PRIVATE KEY-----",
        clientId: "Iv1.YourMagicNumHere",
        clientSecret: "YetAnotherSecretHere",
      });
      
    const auth = await authCreator({ type: "app" });

    return new Octokit(auth);
}