How to get the installation token?
See original GitHub issueI have been banging my head against this for quite a while and I feel like perhaps someone else may know the answer. I need to get an installation token in order to be able to clone down repo code and run static analysis on the files as demonstrated in this guide. However, I just cannot figure out how to get the installation token. What I am trying right now is:
context.github.apps
.createInstallationToken({ installation_id: context.payload.installation.id })
.then(console.log)
.catch(console.error)
However, every time, I get a 401 error about a JWT being unable to be decoded. From poking around here it seems like other people see this when their private key isn’t correct, but the test check I wrote is working, I have double checked that it key is correct, I regenerated it, and I tried both adding the key as an env variable and including it directly in the folder. I’m not sure it is actually a private key issue.
What’s even more pathetic is that I can see clearly in the debug logs that probot itself is making the same request which is returning successfully when it starts up. However, I can’t find a spot where that request is being made in the probot source code, nor have I been able to mine a working installation token off any off the app or context objects.
Help?!
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (7 by maintainers)
Top GitHub Comments
👋 The trick here is to use the app’s authentication to get the installation token.
context.github
is authenticated specifically to make requests on behalf of an installation, so it doesn’t have permission to do things like create new installation tokens.☝️ Thanks Jason, that was it 😃 👆
It’s gonna get easier soon! With
@octokit/auth-app
the correct authentication header gets set automagically based on the request URL 🙌