Error on /slack/oauth_redirect using ExpressReceiver (bolt-js v3.9)
See original GitHub issueDescription
Hi, I’m getting this error when my app redirects to slack/oauth_redirect. I’ve looked at #1335 but I can’t tell if its the same problem. The URLs are all https ones. I recently started using expressReceiver in order to be able to accept post requests from an external source. However, I may be using it incorrectly and thinking all wrong. Any help would be appreciated. Thank you.
[ERROR] OAuth:InstallProvider:0 Error: The state parameter is not for this browser session.
at new InvalidStateError (/Users/shakauser/Desktop/shaka-slack-bot/slack-app/node_modules/@slack/oauth/dist/errors.js:65:47)
at InstallProvider.<anonymous> (/Users/shakauser/Desktop/shaka-slack-bot/slack-app/node_modules/@slack/oauth/dist/install-provider.js:498:39)
at step (/Users/shakauser/Desktop/shaka-slack-bot/slack-app/node_modules/@slack/oauth/dist/install-provider.js:44:23)
at Object.next (/Users/shakauser/Desktop/shaka-slack-bot/slack-app/node_modules/@slack/oauth/dist/install-provider.js:25:53)
at /Users/shakauser/Desktop/shaka-slack-bot/slack-app/node_modules/@slack/oauth/dist/install-provider.js:19:71
at new Promise (<anonymous>)
at __awaiter (/Users/shakauser/Desktop/shaka-slack-bot/slack-app/node_modules/@slack/oauth/dist/install-provider.js:15:12)
at InstallProvider.handleCallback (/Users/shakauser/Desktop/shaka-slack-bot/slack-app/node_modules/@slack/oauth/dist/install-provider.js:462:16)
at /Users/shakauser/Desktop/shaka-slack-bot/slack-app/node_modules/@slack/bolt/dist/receivers/ExpressReceiver.js:166:42
at Layer.handle [as handle_request] (/Users/shakauser/Desktop/shaka-slack-bot/slack-app/node_modules/express/lib/router/layer.js:95:5) {
code: 'slack_oauth_invalid_state'
const receiver = new ExpressReceiver({
token: process.env.SLACK_BOT_TOKEN,
appToken: process.env.SLACK_APP_TOKEN,
port: process.env.PORT || 3030,
signingSecret: process.env.SLACK_SIGNING_SECRET,
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
stateSecret: 'some-shaka-state-secret',
scopes: scopes,
installationStore: {
storeInstallation: async (installation) => {
// change the line below so it saves to your database
if (installation.isEnterpriseInstall && installation.enterprise !== undefined) {
// support for org wide app installation
return await database.set(installation.enterprise.id, installation);
}
if (installation.team !== undefined) {
// single team app installation
return await database.set(installation.team.id, installation);
}
throw new Error('Failed saving installation data to installationStore');
},
fetchInstallation: async (installQuery) => {
// change the line below so it fetches from your database
if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) {
// org wide app installation lookup
return await database.get(installQuery.enterpriseId);
}
if (installQuery.teamId !== undefined) {
// single team app installation lookup
return await database.get(installQuery.teamId);
}
throw new Error('Failed fetching installation');
},
deleteInstallation: async (installQuery) => {
// change the line below so it deletes from your database
if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) {
// org wide app installation deletion
return await database.delete(installQuery.enterpriseId);
}
if (installQuery.teamId !== undefined) {
// single team app installation deletion
return await database.delete(installQuery.teamId);
}
throw new Error('Failed to delete installation');
},
},
installerOptions: {
// If this is true, /slack/install redirects installers to the Slack authorize URL
// without rendering the web page with "Add to Slack" button.
// This flag is available in @slack/bolt v3.7 or higher
directInstall: true,
}
});
receiver.router.use(express.json());
receiver.router.use(cors());
const app = new App({
receiver,
logLevel: LogLevel.DEBUG,
});
receiver.router.get('/', (req, res) => {
res.writeHead(200);
res.end('Home Page!');
});
receiver.router.post('/shaka-events', (req, res) => {
res.json(req.body);
console.log(req.body);
});
What type of issue is this? (place an x in one of the [ ])
- bug
- enhancement (feature request)
- question
- documentation related
- example code related
- testing related
- discussion
Requirements (place an x in each of the [ ])
- I’ve read and understood the Contributing guidelines and have done my best effort to follow them.
- I’ve read and agree to the Code of Conduct.
- I’ve searched for any related issues and avoided creating a duplicate issue.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
@Slack/bolt JS upgrade 2.7.0 to 3.3.0 throws 'An ...
In looking at the @Slack/bolt 3.3.0 source code, the actual error message ... and then instantiates a bolt App() with the ExpressReceiver, ...
Read more >Slack | Bolt for JavaScript
A framework that makes Slack app development fast and straight-forward. With a single interface for Slack's Web API, Events API, ...
Read more >Slack Apps with Bolt.js & Serverless
Let's try something new. Using Joi validators as contracts was easy. The error messages on failed assertions are great too. They include the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh my goodness that fixed it. Thank you so much for taking the time to help me!
Glad to hear that! Let me close this issue now