退回无效的身份验证护照

问题描述 投票:0回答:1

我正在使用下方的以下代码使用通行证来获取oauth令牌:

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;
});

我的问题是,每当我向chat.postMessage api请求时,都会出现以下错误:

{
    "ok": false,
    "error": "invalid_auth"
}

我的完整要求如下:

https://slack.com/api/chat.postMessage?token=xxxxxxxxxxxx&channel=general&text=this is an oauth test...2&pretty=1

知道我哪里出错了吗?

oauth passport.js slack slack-api
1个回答
0
投票

从此方法chat.postMessage的api文档中可以找到here

身份验证的某些方面无法验证。提供的令牌无效或请求来自IP地址不允许发出请求

您需要做的是

  1. 重新生成OAuth令牌。
  2. 确保您具有正确的范围。
  3. 如果您对特定IP范围的访问权限有限,请确保您当前的IP在此范围内。如果有的话,您也可以尝试禁用VPN。
© www.soinside.com 2019 - 2024. All rights reserved.