passport-slack return 无法获取 /auth/slack

passport-slack return Cannot GET /auth/slack

我正在开发具有松弛登录功能的应用程序。

我正在为 OAuth 使用 passport-slack,但在 routing 方面遇到了一些问题 return 无法获取 /auth/slack

我按照 https://github.com/mjpearson/passport-slack 中的步骤一步步操作,但仍然没有成功

我目前的护照代码是这样的,我认为我正确定义了路线

// setup the strategy using defaults
passport.use(new SlackStrategy({
  clientID: environment.SLACK.CLIENT_ID,
  clientSecret: environment.SLACK.CLIENT_SECRET,
  }, (accessToken, refreshToken, profile, done) => {
    done(null, profile);
}));

// path to start the OAuth flow
app.get('/auth/slack', passport.authenticate('slack'));

// OAuth callback url
app.get('/auth/slack/callback',
  passport.authenticate('slack', { successRedirect: '/',
  failureRedirect: '/login' }));

/auth/slack只是一个认证中间件,也就是说所有以/auth/slack开头的路由都会调用这个中间件。

也因为你没有任何 response 这条路线,护照只会调用 next() 功能,所以 Cannot GET /auth/slack

您应该在您的 slack 设置中添加 /auth/slack/callback,当用户登录 slack 后,slack 会将用户重定向到此路由

http://expressjs.com/en/guide/using-middleware.html