-
Notifications
You must be signed in to change notification settings - Fork 245
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
Map a Django User to the slack installation (SlackInstallation) #1166
Comments
Hi @NathanSmeltzer, thank you for asking the question! There are two approaches to customize the OAuth callback handler. 1. Callback OptionsThe first one is to use callback_options in oauth_settings: def success(args: SuccessArgs) -> BoltResponse:
# this args object provides the HTTP request and installation data
# https://tools.slack.dev/bolt-python/api-docs/slack_bolt/oauth/callback_options.html#slack_bolt.oauth.callback_options.SuccessArgs
# you can extract your custom cookie values from request.headers
assert args.request is not None
return BoltResponse(
status=200, # you can redirect users too
body="Your own response to end-users here"
)
app = App(
# others ...
oauth_settings=OAuthSettings(
callback_options=CallbackOptions(success=success),
# others ..
),
) Refer to the following resources for more details:
2. OAuthFlow InheritanceThe second is to inherit OAuthFlow object and override store_installation method to save the installation along with the relavant property in your user object.
Lastly, regarding the documentation suggestion, indeed bolt documents can be more specific about advanced use cases. This can be improved in the future. As for the Django's user object example, I'd like to hold off adding such this time because how a developer handles the OAuth flow could depend on their requirements and there is no universal user table data structure. Once you've completed this task and sharing your knowledge here would be greatly appreciated. I hope this was helpful to you. |
Thank you @seratch! Note: args.request.installation has the team_id and other info inside the success callback slack_app/urls.py:
slack_app/slack_listeners.py:
|
My use case is a SaaS product built with Django where a user can integrate with Slack to receive product notifications. I wish to have a Django User instance as a ForeignKey field on the SlackInstallation model.
Reproducible in:
slack_bolt==1.20.1
slack_sdk==3.32.0
django==4.2.11
Python 3.10.14
OS info
Ubuntu 22.04.3
Steps to reproduce:
Here's the oauth_app/urls.py module.
Note: user_rand_id is just a dummy string in the above code. In my actual project, it's used to look up the Django User instance for updating the SlackInstallation model.
Expected result:
The slack installation's info to be available in the slack_oauth_redirect_handler.
Maybe I'm missing where to look for it, but I can't find anything regarding the team_id, slack channel, or any other install info. I've tried cookies, and Django's request.GET and request.META
Other thoughts
Maybe the Django example could be updated with guidance on how to link a Django User instance to the slack installation. There are a few other issues that ask about similar use cases. bolt-js has an open issue to add documentation for this.
If this approach isn't correct, I'm open to other suggestions. Maybe linking the Django User to the SlackInstallation isn't necessary.
The text was updated successfully, but these errors were encountered: