我如何configurationpassport-github来确认callback用户?

我有一个服务,我的目标是让用户通过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做它的魔术和redirect用户到github。 这很好。 但是,当他们返回到/auth/github/callback ,我需要仍然能够确定是哪个用户。

由于这是API服务,所以它应该是无状态的,所以正如我之前提到的,我正在寻找一些方法将该标记传递给/auth/github/callback 。 我怎样才能做到这一点?

在/ auth / github / callback中尝试req.user的控制台日志。 我相信req.user仍然会存储他们的用户信息。 在本教程中,他们通过传递req.user来传递用户信息。