Node.js 如何配置passport github以在回调时确认用户?

Node.js 如何配置passport github以在回调时确认用户?,node.js,coffeescript,oauth-2.0,passport.js,Node.js,Coffeescript,Oauth 2.0,Passport.js,我有一个服务,我的目标是让用户通过OAuth授权我们访问他/她的Github帐户。API层是无状态的,所以我不想维护任何会话信息。到目前为止,我掌握的代码是: app.use passport.initialize() app.use passport.session() passport.use new GitHubStrategy clientID: global.config.oauth.github.clientID clientSecret: global

我有一个服务,我的目标是让用户通过OAuth授权我们访问他/她的Github帐户。API层是无状态的,所以我不想维护任何会话信息。到目前为止,我掌握的代码是:

  app.use passport.initialize()
  app.use passport.session()

  passport.use new GitHubStrategy
    clientID: global.config.oauth.github.clientID
    clientSecret: global.config.oauth.github.clientSecret
    callbackURL: "http://localhost:9500/auth/github/callback"
    passReqToCallback: true
  , (req, accessToken, refreshToken, profile, done) ->
    console.log req.params
    serviceQuery =
      service: 'github'
      provider_id: "#{profile.id}"
      UserId: 13

    global.db.Service.find
      where: serviceQuery
    .then (dbService) ->
      if not dbService
        newService =
          service: 'github'
          token: accessToken
          secret: null
          provider_id: profile.id
          raw: profile._json
          UserId: 13
        global.db.Service.create newService
      else
        dbService.token = accessToken
        dbService.raw = profile._json
        dbService.save()
    .then ->
      done null, true


  app.get '/auth/github/:sessionToken', (req, res, next) ->
    console.log req.params
    next()
  , passport.authenticate 'github',
    scope: 'repo'
    session: false

  app.get '/auth/github/callback', passport.authenticate('github',
    scope: 'repo'
    session: false
  ), (req, res) ->
    res.redirect 'http://localhost:8080/app'
因此,当用户被定向到
/auth/github/:sessionToken
时,我希望
passport
发挥其魔力,将用户重定向到github。这很有效。但是当他们返回到
/auth/github/callback
时,我仍然需要能够识别它是哪个用户


由于这是API服务,它应该是无状态的,所以正如我前面提到的,我正在寻找某种方法将该令牌传递给
/auth/github/callback
。如何实现这一点?

在/auth/github/callback中尝试req.user的控制台日志。我相信req.user仍然会存储他们的用户信息。正如中显示的那样,他们通过传入请求用户来传递要显示的用户信息。

实际上显示了如何显示来自google身份验证的信息。google信息似乎显示在user.google变量中。也许可以尝试通过控制台登录req.user.github来获取他们的github信息。但是如果我没有设置会话,它怎么能存储它呢?