Skip to content

Add bot|user_scopes to context.authorize_result set by SingleTeamAuthorization - #1104

Merged
seratch merged 2 commits into
slackapi:mainfrom
seratch:add-scopes-to-context
Jul 3, 2024
Merged

Add bot|user_scopes to context.authorize_result set by SingleTeamAuthorization#1104
seratch merged 2 commits into
slackapi:mainfrom
seratch:add-scopes-to-context

Conversation

@seratch

@seratch seratch commented Jul 2, 2024

Copy link
Copy Markdown
Contributor

This pull request improves the built-in SingleTeamAuthorization middleware to attach bot|user_scopes to Request#Context#AuthorizeResult as MultiTeamsAuthorization does.

Why does this matter? This property is useful specifically when you want to know the issued OAuth token, which is associated with an incoming Slack event request, has sufficient scopes for newly added feature in a Slack app. Here is an example: https://github.com/seratch/ChatGPT-in-Slack/blob/341f50ad00f853009f3c50ff6c3133d6fd0b3dd7/app/bolt_listeners.py#L1053-L1065

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 the bug Something isn't working label Jul 2, 2024
@seratch seratch added this to the 1.19.1 milestone Jul 2, 2024
@seratch seratch self-assigned this Jul 2, 2024
@codecov

codecov Bot commented Jul 2, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.79%. Comparing base (ce27780) to head (866b562).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1104      +/-   ##
==========================================
+ Coverage   91.77%   91.79%   +0.01%     
==========================================
  Files         186      186              
  Lines        6407     6408       +1     
==========================================
+ Hits         5880     5882       +2     
+ Misses        527      526       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Neat find 💯
Changes look good to me 👍 left one comment but it isn't a blocker

bot_token=token if _is_bot_token(token) else None,
user_id=request_user_id or (user_id if not _is_bot_token(token) else None),
user_token=token if not _is_bot_token(token) else None,
bot_scopes=auth_test_result.headers.get("x-oauth-scopes", []) if _is_bot_token(token) else None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Defining a scope = auth_test_result.headers.get("x-oauth-scopes", []) variable, similar to user_id = auth_test_result.get("user_id") may make this section clearer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion!

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

++ to a nice find! The code and tests look great to me! 🎉

@seratch

seratch commented Jul 3, 2024

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews!

@seratch
seratch merged commit e2505bf into slackapi:main Jul 3, 2024
@seratch
seratch deleted the add-scopes-to-context branch July 3, 2024 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants