-
Notifications
You must be signed in to change notification settings - Fork 275
Description
First of all, loving the Slack Bolt dev experience. And really appreciate the community and responsiveness from maintainers.
I have put this as a question because I'm pretty sure I am missing a fundamental Oauth step here - I just can't figure it out.
As described in the Expected Result section below, I am trying to create an App that is both a Bot and also uses the Web API that requires user_tokens. The Bot and Home page are meant to be present regardless of whether the user has a user_token stored or not - the Home Page UI and Bot responses will just depend on whether the user_token exists. While I have the whole setup working, the flow is really choppy. I can create the App for the workspace, however when a user then goes to interact with the App (either via the Home page or the Bot), the Bolt App returns the error slack_bolt.MultiTeamsAuthorization:Although the app should be installed into this workspace, the AuthorizeResult (returned value from authorize) for it was not found.
Note that if the user first goes to the /slack/install route from a browser, the user_tokens are generated and if you allow Slack to be opened, the permissions are recognised and the user can interact with the App's advanced functionality that requires the user_tokens
I know from the Bolt docs that apps that span multiple workspaces may require an authorize function, however I had never selected or implied that this was a multi-workspace app, so I am unsure why the App is expecting an AuthorizeResult returned.
I also know there have been similar questions asked before, however what I am experiencing is that this error is introduced before any of the event callbacks are triggered. Ie. I can't do any of my own validation on the "app_home_opened" event callback as this is never triggered, and thus I don't have access to the client object unless I recreate one somehow. As you can see in the screenshot below, the only object I have access to currently (without the custom authorize function) is the initial Request json. Even the Oauth_flow callbacks are not triggered (where I could also set some custom logic), which suggests this MultiTeamsAuthorization error occurs before the Oauth_flow is validated.
Is my only solution for this to create a custom authorize function to handle all of the permission checks each time? This is not ideal as one of the advantages of using Bolt is that it handles the Oauth protocol and token verification for us, which I would like to avoid writing myself (and possibly introducing security vulnerabilities)
Many thanks for any guidance available
Reproducible in:
- Sample code here: https://gist.github.com/stantonius/d6a115a657126ef5a9e6d942ff01a9d1
- Ngrok tunnel
- Local FastAPI server as per instructions:
uvicorn main:api --reload --port 3000 --log-level warning
The slack_bolt version
slack-bolt==1.11.1
slack-sdk==3.13.0
Note that FastAPI adapter is used
Python runtime version
3.9.9
OS info
ProductName: macOS
ProductVersion: 12.0.1
BuildVersion: 21A559
Steps to reproduce:
See below
Expected result:
- App is installed to entire workspace. Bot token is generated and embedded in the Bolt code
- User interacts with Bot to understand its advanced functionality. Bot evaluates whether there is a user_token for each user.
- If yes, the advanced App functionality is presented to the user.
- If no, the Home Page explains the App, its rationale for permissions, and has the Install button embedded. The App's Bot is available to address general questions about it and its features. Once the Install is complete, the Home page then loads with the advanced features, since the user_token has been generated
Actual result:
- App is installed to entire workspace. Bot token is generated and embedded in the Bolt code
- User clicks on the App (to see either the Home page or interact with the Bot), and the Bolt Python App returns the error
slack_bolt.MultiTeamsAuthorization:Although the app should be installed into this workspace, the AuthorizeResult (returned value from authorize) for it was not found.The Home page never loads and the Bot is not functional.
