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

How to pass parameters in redirect_uri or install url? #1428

Closed
2 of 6 tasks
Kunal951996 opened this issue Feb 17, 2022 · 3 comments
Closed
2 of 6 tasks

How to pass parameters in redirect_uri or install url? #1428

Kunal951996 opened this issue Feb 17, 2022 · 3 comments
Labels
pkg:oauth applies to `@slack/oauth-helper` question M-T: User needs support to use the project
Milestone

Comments

@Kunal951996
Copy link

Kunal951996 commented Feb 17, 2022

Let's say I want to save the data received after redirect_url and I want to save it against specific user Id. For that how can I pass parameters in install url and maintain it when receiving request from redirect url?

Packages:

Select all that apply:

  • @slack/web-api
  • @slack/rtm-api
  • @slack/webhooks
  • @slack/oauth
  • @slack/socket-mode
  • I don't know

Reproducible in:

npm ls | grep -o "\S\+@\S\+$" | tr @ ' ' | awk -v q='"' '{print q$1q": "q"^"$2q","}' | grep slack
node --version
sw_vers && uname -v # or `ver`

The Slack SDK version

(Paste the output of

npm ls | grep -o "\S\+@\S\+$" | tr @ ' ' | awk -v q='"' '{print q$1q": "q"^"$2q","}' | grep slack

or refer to your package.json)

Python runtime version

(Paste the output of node --version)

OS info

(Paste the output of sw_vers && uname -v on macOS/Linux or ver on Windows OS)

Steps to reproduce:

(Share the commands to run, source code, and project settings)

Expected result:

(Tell what you expected to happen)

Actual result:

(Tell what actually happened with logs, screenshots)

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. 🙇

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

@mwbrooks mwbrooks added question M-T: User needs support to use the project pkg:oauth applies to `@slack/oauth-helper` and removed untriaged labels Feb 17, 2022
@mwbrooks
Copy link
Member

mwbrooks commented Feb 17, 2022

Hey @Kunal951996, thanks for taking the time to reach out 👋🏻

Passing state data with the OAuth module is a little awkward and we're in the process of improving it (release coming soon).

For now, you will want to use the OAuth metadata feature to pass data from the install URL to the success redirect_uri. For example:

  1. Create a install route such as /app/install or /slack/install (but not the built-in version)
  2. Inside the route, generate a dynamic url with the user's metadata
  3. Use a custom success handler to parse the metadata

A rough code sample may look like:

app.get('/slack/install', async (req, res, next) => {
  try {
    const url = await installer.generateInstallUrl({
      scopes: ['channels:read', 'groups:read', 'channels:manage', 'chat:write', 'incoming-webhook'],
      metadata: 'some_metadata',
    });

    res.send(`<a href=${url}><img alt=""Add to Slack"" height="40" width="139" src="https://platform.slack-edge.com/img/add_to_slack.png" srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platform.slack-edge.com/img/add_to_slack@2x.png 2x" /></a>`);
  } catch(error) {
    console.log(error);
  }
});

const callbackOptions = {
  success: (installation, options, req, res) => {
    console.log(options.metadata);
    res.send('successful!');
  },
  failure: (error, installOptions , req, res) => {
    res.send('failure');
  },
}

app.get('/slack/oauth_redirect', async (req, res) => {
  await installer.handleCallback(req, res, callbackOptions);
});

Hope that helps!

@filmaj
Copy link
Contributor

filmaj commented Mar 3, 2022

FYI the release candidate for oauth@2.5.0-rc.1 is live on npm (you will need to install it referencing the version directly like so: npm i @slack/oauth@2.5.0-rc.1), but I will leave this issue open as I think we still need to add documentation for the new methods we have exposed in this release candidate. Once we have docs in place we will post here and close this issue.

@seratch
Copy link
Member

seratch commented Mar 25, 2022

The latest version v2.5.0 supports more callbacks to customize your OAuth flow. Refer to the "Persisting data during the OAuth flow" section in the updated document: https://slack.dev/node-slack-sdk/oauth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:oauth applies to `@slack/oauth-helper` question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

4 participants