我正在使用下方的以下代码使用通行证来获取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
知道我哪里出错了吗?
从此方法chat.postMessage
的api文档中可以找到here。
身份验证的某些方面无法验证。提供的令牌无效或请求来自IP地址不允许发出请求
您需要做的是
OAuth
令牌。