Reputation: 1377
I'm using passportjs to obtain an oauth token using the following code below:
const SlackStrategy = require('passport-slack-oauth2').Strategy;
/* configure passport to work with Slack */
passport.use(new SlackStrategy({
clientID: SLACK_CLIENT_ID,
clientSecret: SLACK_CLIENT_SECRET,
scope: [
'chat:write:user',
],
callbackURL: SERVER_DOMAIN+"/api/strategy/slack/callback"
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}
));
router.get('/authorize', function(req, res, next) {
req.session.workflowId = req.query.workflowId;
passport.authenticate('slack', function(err, user, info) {
next();
})(req, res, next);
});
/* OAuth Callback flow */
router.get('/callback', passport.authorize('slack', { failureRedirect: '/authorize' }), function(req, res) {
const accessToken = req.query.code;
});
My problem is that whenever I make a request to the chat.postMessage
api, I get the following error:
{
"ok": false,
"error": "invalid_auth"
}
My full request looks like this:
https://slack.com/api/chat.postMessage?token=xxxxxxxxxxxx&channel=general&text=this is an oauth test...2&pretty=1
Any idea where I went wrong?
Upvotes: 1
Views: 1930
Reputation: 53
Not sure if you are doing this here, but if you use os environmental variables, please ensure they are correct and refreshed. I had such issue, but working with Golang. You can simply print the token for a test.
Upvotes: 0
Reputation: 1821
From the api documentation for this method chat.postMessage
that can be found here.
Some aspect of authentication cannot be validated. Either the provided token is invalid or the request originates from an IP address disallowed from making the request
What you need to do is
OAuth
token.Upvotes: 1