Incorporating Slack-bolt django example in my app

48 Views Asked by At

I have incorporated slack-bolt Django example in my Django project. I can successfully install the app using /slack/install. However, I have challenges with customisation.

My app is initialised as in the django example

app = App(
    signing_secret=signing_secret,
    oauth_settings=OAuthSettings(
        client_id=client_id,
        client_secret=client_secret,
        scopes=scopes,
        user_scopes=user_scopes,

        # If you want to test token rotation, enabling the following line will make it easy
        # token_rotation_expiration_minutes=1000000,
        installation_store=DjangoInstallationStore(
            client_id=client_id,
            logger=logger,
        ),
        state_store=DjangoOAuthStateStore(
            expiration_seconds=120,
            logger=logger,
        ),
    ),
)

Challenge 1:

I would like the installation flow to be triggered from the /profile page of my app. I generated the Slack install button and placed it inside of my app /profile page. Please note that the profile page is available to the user after authentication to the django project.

When the user gets redirected, the Slack page shows up, user clicks Allow and is redirected back to the /slack/oauth_redirect The error shows up with information that Slack installation was triggered from a different URL than /slack/install.

I tried to set the installation_url in my app as follows app.oauth_flow.install_path = '/profile' app.oauth_flow.settings.install_path = '/profile'

but it didn't work

The only way I could make it work was to disable the state validation app.oauth_flow.settings.state_validation_enabled = False

Question 1: How do I set up a custom URL from which Slack app installation can be triggered?

Question 2: How do I generate the URL in a way that state is properly managed? (Currently I simply use the generated install button HTML code in my django template).

I will appreciate a code example showing how to do it.

Challenge 2:

When the user approves the Slack app scopes, user is redirected back to /oauth_redirect to complete the app installation (save the data the database). I would like the user to be redirected back to the /profile page after all the settings are saved with additional query string parameters for successful and failed installation.

I tried setting up the following but it doesn't work

app.oauth_flow.settings.redirect_uri = "/profile"

app.oauth_flow.settings.success_url = "/profile?slack_install=1"

app.oauth_flow.settings.failure_url = "/profile?slack_install=0"

Question: How do I redirect the user back to my app URL from bolt django /oauth_redierect page?

Reproducible in: The slack_bolt version slack-bolt==1.18.1

Python runtime version Python 3.9.5

OS info ProductName: macOS ProductVersion: 14.2.1 BuildVersion: 23C71 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103

I tried changing oauth_flow settings but without any success.

0

There are 0 best solutions below