Viper
Viper

Reputation: 1377

Slack returning invalid_auth passport

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

Answers (2)

Mat21445
Mat21445

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

Caleb Njiiri
Caleb Njiiri

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

  1. Regenerate the OAuth token.
  2. Ensure that you have the right scopes.
  3. If you have limited access to specific IP ranges ensure you current IP is within this range. You can also try disabling your VPN if you have any.

Upvotes: 1

Related Questions