Replies: 2 comments 11 replies
-
You start out with const { Octokit } = require("@octokit/rest");
const { createAppAuth } = require("@octokit/auth-app");
const appOctokit = new Octokit({
authStrategy: createAppAuth,
auth: {
appId: 123,
privateKey: process.env.PRIVATE_KEY,
// optional: this will make appOctokit authenticate as app (JWT)
// or installation (access token), depending on the request URL
installationId: 123,
},
});
You can use any other auth plugin the same way, instead of using Here are the docs for |
Beta Was this translation helpful? Give feedback.
-
tl;dr - try thisconst { Octokit } = require("@octokit/core");
const { paginateRest } = require("@octokit/plugin-paginate-rest");
const MyOctokit = Octokit.plugin(paginateRest).defaults({ userAgent: "my-app-name" });
const oauthToken = Buffer.from([process.env.CLIENT_ID, process.env.CLIENT_SECRET].join(':')).toString('base64')
const octokit = new MyOctokit({ auth: `basic ${oauthToken}` });
octokit.paginate("GET /users/{username}/repos", { username: "Martii" }).then(repositories => {
console.log("%d repositories found", repositories.length)
})
😱Wow, that's been ... a while
The authentication strategies such as There were a ton of changes to REST API the methods since the What I would suggest is to migrate to The benefit is that the REST API endpoints barely change. You get full TypeScript support, too, the same as using the REST API methods: It looks like you use endpoints that paginate, in that case I would recommend to use the paginate plugin:
I think this is actually a bug. When using with an OAuth App, it should set the apps clientId/clientSecret as basic authentication in order to bump the rate limit. I'll create a follow up issue to look into that. I've recently split up For the time being, can you try this const oauthToken = Buffer.from([process.env.CLIENT_ID, process.env.CLIENT_SECRET].join(':')).toString('base64')
const octokit = new Octokit({
auth: `basic ${oauthToken}`,
}); That should work, I didn't test it though.
This is the code you get from the OAuth web flow, as you found out. This code expires quickly, there is no use in storing it, it's meant to be exchanged immediately for an OAuth user access token, which is what |
Beta Was this translation helpful? Give feedback.
-
So our project is currently using the old github dependency and we've been trying to migrate to the latest usage for the GitHub API v3... however...
There are a bazillion questions... here are some things done...
require
name which of course doesn't work. However the auth-oauth-app says use https://www.npmjs.com/package/@octokit/core ... which ones?access_token
needed to test if https://www.npmjs.com/package/@octokit/auth-oauth-app#usage-with-octokit ... so not sure what to do with this yet.My main question is where the heck do I start with what packages for migration? i.e. obviously we want the larger rate limit (we'll skip PAT for now and use our app OAuth) but there doesn't seem to be any clear, and current, documentation on migration.
Please help.
P.S. I've also searched the web and got a lot of outdated articles or way too general. I've also reached out to the original contributor and of course he's gone dark which isn't helpful.
Beta Was this translation helpful? Give feedback.
All reactions