1

I'm unable to authenticate as an app using Octokit/rest and the documentation as failed me...

Here's my routine for authenticating:

async function getGithub({payload}) {
  const auth = createAppAuth({
    id: parseInt(process.env.APP_ID, 10),
    privateKey: getPrivateKey()
  })

  const installationAuth = await auth({
    type: 'installation',
    installationId: payload.installation.id,
  })

  return new Octokit(installationAuth)
}

Could anybody point me in the right direction?

When I make a request with the client, I just get a 404. I know the repo exists and Github's docs point out that unauthorised requests may result in a 404 if the client has no access.

hjfitz
  • 399
  • 4
  • 15

1 Answers1

2

I've solved it!

I wasn't passing the right information to the bot. The working function looks like this.

async getGithub(context) {
  const auth = createAppAuth({
    id: parseInt(process.env.APP_ID, 10),
    privateKey: getPrivateKey()
  })

  const installationAuth = await auth({
    type: 'installation',
    installationId: context.payload.installation.id,
  })

  return new Octokit({
    auth: installationAuth.token // directly pass the token
  })
}

So close!

hjfitz
  • 399
  • 4
  • 15
  • If you think there is any potential improvement which could be applied to probot to help us as users, please feel free to open an issue on Github :) – OscarDOM Aug 06 '20 at 09:15