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.

Using the built-in OAuth, how can I access the rest of the fetched Installation from a listener?

See original GitHub issue

Description

The built in OAuth is super convenient and great! It fetches the appropriate Installation from my InstallationStore and uses the tokens in that installation to authorize the incoming events. It also puts the relevant User ID and Bot User ID in context so I can access it from middleware and listeners.

But the Installation has so much more in it than just those properties. For example, the installed scopes are stored, an incoming webhook may be stored, etc. If I wanted to access these, I’d currently have to perform installationStore.fetchInstallation() again inside my listener. The framework did that already though, so that’s a waste.

This could be solved in probably a few different ways, but I think one of the simplest would just be to add a new (optional) property called installation on AuthorizeResult. The implementation of authorize() that the built-in OAuth library uses would set that property to the whole Installation it got from fetchInstallation(). Any custom authorize() implementations could also set this value. That installation property would then be added to the context, just like botToken, userToken, etc. Then listeners and middleware could use any installation data.

Requirements (place an x in each of the [ ])

  • I’ve read and understood the Contributing guidelines and have done my best effort to follow them.
  • I’ve read and agree to the Code of Conduct.
  • I’ve searched for any related issues and avoided creating a duplicate issue.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
seratchcommented, May 10, 2021

@willyxiao

the current default authorize function looks like it’s making a call to slack (via client.auth.test on line 890 in App.ts).

This is only for the case where you pass a token in App constructor. In this case, your app works only for a single workspace , so that it uses singleAuthorization for its authorize. This is not the case you mentioned here. https://github.com/slackapi/bolt-js/blob/9867e382e94646b518d05c3e71d7947aad699692/src/App.ts#L359-L367

Is that what’s ultimately calling fetchInstallation as I see in my logs, or am I misunderstanding? If I am, where is fetchInstallation called now?

If your app enables OAuth and its installation store functions, Bolt uses the HTTPReceiver’s default authorize function for OAuth: https://github.com/slackapi/bolt-js/blob/9867e382e94646b518d05c3e71d7947aad699692/src/App.ts#L375 This authorize function calls fetchInstallation internally.

tokenVerificationEnabled

tokenVerificationEnabled is a flag option for turning the eager verification of the given token value in App constructor on/off. Therefore, this is not an option for you. This option works only with the bult-in singleAuthorization.

Although it’s not active recently, this is an issue for bolt-js’s enhancement discussion. If you have followup questions or related ones, would you mind creating a new issue for your question or asking them in the Slack Platform Community workspace? In the community workspace, #lang-javascript #tools-bolt would be good places to have this type of Q&A. I would appreciate it if you could understand this!

0reactions
LeoDODcommented, May 24, 2022

is there an estimated release date for 4.x?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build a Simple REST API with Node and OAuth 2.0
Today, I'll show you how to create a REST API using Node.js, and secure it with OAuth 2.0 to prevent unwarranted requests. REST...
Read more >
Bolt for JavaScript - Slack Platform Developer Tools
To listen to messages that your app has access to receive, you can use the message() method which filters out events that aren't...
Read more >
Authentication and authorization - Apollo GraphQL Docs
The example below extracts a user token from the HTTP Authorization header included in each operation request. It then fetches the corresponding user...
Read more >
OAuth 2.0 for Client-side Web Applications - Google Developers
In this flow, your app opens a Google URL that uses query parameters to identify your app and the type of API access...
Read more >
Backend For Frontend Authentication Pattern with Auth0 and ...
The client type will determine one or more OAuth flows suitable for the application implementation. By sticking to one of those flows, you...
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