question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get the installation token?

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

15reactions
JasonEtcocommented, Sep 3, 2019

👋 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.

app.on('event', async context => {
  const github = await app.auth() // Not passing an id returns a JWT-authenticated client
  const token = await github.apps.createInstallationToken({ installation_id: context.payload.installation.id })
})
4reactions
gr2mcommented, Sep 3, 2019

☝️ 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 🙌

Read more comments on GitHub >

github_iconTop Results From Across the Web

installation-tokens | Sumo Logic Docs
Click the + Add Token button on the top right of the table. A panel named Create Installation Token appears to the right...
Read more >
How to Obtain an Installation Token for Dell Threat Defense
From a web browser, go to the Dell Threat Defense administration console at: North America: https://dellthreatdefense.cylance.com.
Read more >
Authenticating with GitHub Apps
Before authenticating as an installation, you must create an installation access token. Ensure that you have already installed your GitHub App to at...
Read more >
Copy installation token - Cylance - BlackBerry Docs
Copy installation token · Using a web browser, log in to. CylanceON-PREM . · Click. Settings . · Copy the Installation Token.
Read more >
Installation Access Token - UiPath Documentation Portal
Installation Access Token ... Identity Server allows you to register other UiPath on-premise products, called clients, for Single Sign-On with Orchestrator. This ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found