GithubHelp home page GithubHelp logo

Comments (6)

gr2m avatar gr2m commented on June 14, 2024

The 404 error is see is not coming from the GET /app/orgs/:org/projects request, but from POST https://api.github.com/app/installations//access_tokens. The createAppAuth strategy is sending the request to retrieve an installation token automatically for you, you don't need to do that manually.

What you need to do though is to set the auth.installationId option.

Try this

new Octokit({
  authStrategy: createAppAuth,
  auth: {
    id: process.env.GITHUB_APP_ID,
    privateKey: pemKey,
    installationid
  },
  userAgent: "blabla",
  previews: ["inertia"],
});

await session.request("GET /app/orgs/:org/projects", {
  headers: {
    authorization: `token ${installToken}`,
  },
  org,
});

from request.js.

PierFio avatar PierFio commented on June 14, 2024

Thanks a lot for the fast help and this whole framework. That way, it works. Surprisingly (I was looking at that), this is not working though:

const sessionMaker = Octokit.defaults({
     authStrategy: createAppAuth,
      auth: {
          id: process.env.GITHUB_APP_ID,
          privateKey: pemKey,
      },
      userAgent: 'blabla',
      baseUrl: 'https://api.github.com',
      previews: ['inertia', 'machine-man'],
});

followed by

const session = new sessionMaker(options =>  
    ({
         ...options,
         auth: {
            ...options.auth,
            installationId,
            permissions: {
                organization_projects: 'write',
            }
         },
    })
);

from request.js.

gr2m avatar gr2m commented on June 14, 2024

you are passing a function to sessionMaker, try passing the options object instead

const session = new sessionMaker({
  ...options,
  auth: {
    ...options.auth,
    installationId,
    permissions: {
      organization_projects: "write",
    },
  },
});

from request.js.

PierFio avatar PierFio commented on June 14, 2024

Yes, thank you, you are right of course. But do not you think that defeats the purpose of the default options? I mean I have defined a defaultOptions object that I specialize when calling a specific new Octokit(). But certainly not a big deal anyway...

from request.js.

gr2m avatar gr2m commented on June 14, 2024

You can create a constructor which has the app auth strategy and app ID + private key configured

const OctokitWithAppAuth = Octokit.defaults({
  authStrategy: createAppAuth,
  auth: {
    id: process.env.GITHUB_APP_ID,
    privateKey: pemKey,
  },
});

Then use that custom constructor to initiate instances for an installation

const octokit = new OctokitWithAppAuth({
  auth: {
    installationId
  },
});

from request.js.

PierFio avatar PierFio commented on June 14, 2024

Neat and nice. Thank you Gregor.

from request.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.