Given a JWT, how do you create an octokit client from it? Using NodeJS.
Asked
Active
Viewed 269 times
0
-
https://github.com/octokit/auth-app.js/ ? I don't understand it, let's get a concise example up here on stackoverflow – Johnny5 Apr 19 '21 at 23:38
1 Answers
1
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);
}

Johnny5
- 463
- 2
- 5
- 16