我正在为Slack构建一个带有附加Web界面/团队仪表板的应用程序 . 内置节点,我正在努力让Slack auth和Client auth成为一个流畅的动作 .

我使用passport.js进行身份验证,使用Slack策略验证用户是否在Slack中使用该应用程序(使用 Sign in with Slack 按钮) . 这个Slack auth 's callback contains all of the user information I' d需要,所以我想用它来验证用户在Web客户端访问他们团队的仪表板 . 这就是JWT发挥作用的地方 .

这是我第一次使用JWT auth,但从理论上讲,有一种方法可以使用护照的JWT策略为客户端进行身份验证 .

这是护照Slack策略的代码,工作正常:

passport.use(
  new SlackStrategy(
    {
      clientID: process.env.SLACK_CLIENT_ID,
      clientSecret: process.env.SLACK_CLIENT_SECRET,
      scope: [
        'identity.basic',
        'identity.avatar',
        'identity.email',
        'identity.team',
        'users.list',
        'chat:write:bot',
      ],
      skipUserProfile: false,
    },
    (accessToken, scopes, team, extra, profiles, done) => {
      if (extra.bot != null) {
        Team.postTeamOnInstall(team, extra.bot.accessToken)
      } else {
        User.postUser(accessToken, profiles)
      }
      done(null, {})
    }
  )
)

app.get(
  '/auth/slack',
  passport.authenticate('slack', {
    scope: ['bot'],
  })
)

app.get(
  '/auth/slack/callback',
  passport.authenticate('slack', { session: false }),
  (req, res) => {
    // what if called JWT authentication here? that then redirects to the team dashboard
    res.redirect(`http://${process.env.BASE_URL}`)
  },
  (err, erq, res, next) => {
    res
      .status(500)
      .send(`<p>Think Fish failed to install</p> <pre>${err}</pre>`)
  }
)

现在我跟着basic tutorial for the JWT strategy . 所以我在这方面的代码看起来与此相同 . 我真的只想知道:

1)有没有人这样或类似的东西?我是否正确地思考这个问题?这可能吗?

2)如果是这样,Slack StrategyJWT Strategy如何相互通信以获得Slack和客户端在一个流体运动中验证的用户( Sign in with Slack 按钮)?

我也可能过度设计这个,而只是需要某种方式来安全路由来检查用户是否已经登录Slack?