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
Comments
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:
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! |
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: |
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 |
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
Reproducible in:
The Slack SDK version
(Paste the output of
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 orver
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.
The text was updated successfully, but these errors were encountered: