Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the built-in authorize for better support of user-scope only installations #576

Merged
merged 3 commits into from Jan 17, 2022

Conversation

seratch
Copy link
Member

@seratch seratch commented Jan 15, 2022

While answering the question at #574, I found that there is room for improvement in the InstallationStoreAuthorize module. This pull request improves the internals to cover the following situation:

  • An app has two paths of app installations
    • App installation with bot scopes (plus user scopes is optional) /slack/install
    • User scope installation with individual users /slack/user_install
  • The admin user A installed the app into the workspace with bot token and the person's user scopes
  • End-user B installed the app to grant user scopes to the app from /slack/user_install
  • The app receives an incoming request associated with user B

In this scenario, the authorize function should return the bot token generated by admin user A plus the user B's user token in AuthorizeResult. However, the current implementation returns only user B's user token.

This pull request resolves the issue, plus improved the readability of the code by renaming local variables and adding more comments.

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

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements (place an x in each [ ])

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

  • 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 run ./scripts/install_all_and_run_tests.sh after making the changes.

@seratch seratch added bug Something isn't working area:async area:sync labels Jan 15, 2022
@seratch seratch added this to the 1.12.0 milestone Jan 15, 2022
@seratch seratch self-assigned this Jan 15, 2022
@codecov
Copy link

codecov bot commented Jan 15, 2022

Codecov Report

Merging #576 (e939a56) into main (0ee6bb7) will increase coverage by 0.15%.
The diff coverage is 91.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #576      +/-   ##
==========================================
+ Coverage   91.33%   91.48%   +0.15%     
==========================================
  Files         169      169              
  Lines        5665     5699      +34     
==========================================
+ Hits         5174     5214      +40     
+ Misses        491      485       -6     
Impacted Files Coverage Δ
slack_bolt/app/app.py 87.69% <ø> (ø)
slack_bolt/app/async_app.py 94.19% <ø> (ø)
slack_bolt/authorization/async_authorize.py 83.94% <90.90%> (+4.77%) ⬆️
slack_bolt/authorization/authorize.py 83.70% <91.17%> (+4.89%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0ee6bb7...e939a56. Read the comment docs.

Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, but damn, this gets complicated fast! 🙈

:shipit:


if installation is not None:
if installation.user_id != user_id:
# If the user_token in the latest_installation is not for the user associated with this request,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we can provide an example of when the situation described in this comment arises (i.e. via the situation described in #574) it may give helpful context to future maintainers reading through this code. I have just now freshly read up on the issue and PR and I am already confused by this rather complex use case! 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I don't think we should add a very long comment here but I will add a bit more details here before merging this.

@@ -294,3 +307,28 @@ def _debug_log_for_not_found(
"No installation data found "
f"for enterprise_id: {enterprise_id} team_id: {team_id}"
)

async def _rotate_and_save_tokens_if_necessary(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:async area:sync bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants