slackapi / bolt-js

A framework to build Slack apps using JavaScript
https://tools.slack.dev/bolt-js/
MIT License
2.74k stars 393 forks source link

After a user installs my Slack app I want to redirect them to my web app, hosted on a different domain #1703

Closed MattB543 closed 1 year ago

MattB543 commented 1 year ago

Description

After a user installs my Slack app I want to redirect them to my web app which is hosted on a different domain, is that possible?

Currently, if I pass my Slack app installation domain as the redirect_uri everything works perfectly.

If I try to update the redirect_uri to be my front-end domain it properly redirects and displays no errors, yet it's not installing the app on the workspace anymore...

Is there something I'm missing in the bolt config?

What type of issue is this? (place an x in one of the [ ])

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


Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version: @slack/bolt": "3.11.1

node version: v18.12.1

OS version(s):

Steps to reproduce:

  1. Set the redirectUri & redirectUriPath to a domain that isn't hosting the Slack app

Expected result:

The Slack app installs on the workspace and redirects to the domain I set as the redirectUri which is my web app front-end. The front end passes the state and code to the backend and signs the user directly into my web app.

Actual result:

The Slack app does not install on the workspace.

Attachments:

seratch commented 1 year ago

Hi @MattB543, thanks for asking the question. You can use CallbackOptions.success for it. Refer to https://github.com/slackapi/bolt-js/issues/1571#issuecomment-1231795209 for more details. In your case, you can redirect an installing user to a different domain instead of rendering the webpage.

themashcodee commented 1 year ago

Hi, @seratch thanks for the reply.

Actually, we want our user to automatically log in to our application with slack OpenID authorization https://slack.com/openid/connect/authorize.

So in order to do that we need a code that OpenID authorization returns to the redirect URI, so how we can get it from the app installation?

seratch commented 1 year ago

@themashcodee An app installation into a Slack workspace is indeed an OAuth flow, but it's not compatible with OpenID Connect including the "Sign in with Slack" one. So, if you need an OpenID Connect response, the user needs to go through the Sign in with Slack flow separately. Also, unfortunately, bolt-js does not support Sign in with Slack. You need to add custom routes (or build a different app) for the Sign in with Slack flow. Refer to an example app directly using the underlying @slack/oauth package: https://github.com/slackapi/node-slack-sdk/tree/main/examples/openid-connect

Lastly, if the reason you're considering "Sign in with Slack" is to receive the installing user's identity, the app installation flow's oauth.access.v2 API response already provides it. If that's the case, you may not have to add the OpenID Connect flow to the app.

I hope this helps.

themashcodee commented 1 year ago

@seratch thank you so much for the help, I really appreciate it.

MattB543 commented 1 year ago

Thanks, @seratch , appreciate your quick response!