我如何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来传递用户信息。
- child_process.exec / spawn使用npm install命令(通过Gulp / Shipit)触发callback/closures
- iojs中是否会有一个兼容ES6的模块系统(导入/导出)?
- 在nodejs / commonjs中用coffeescript(zappa)重新导出模块(mongoose)
- Node.js:使用CoffeeScript创build一个Express项目
- node-orm同步到Alter Tables(类似于DataMapper.auto_upgrade)
- NodeJS + CoffeeScript,根据请求渲染coffeescript编译的js
- 如何从asynchronous调用中返回值
- 从誓言启动服务器进行testing的正确方法是什么?
- 将jadeify添加到node-express-browserify项目中
- 如何sorting内部数组和mongoose中的元素
- glob在Node.js中只返回匹配(无前导path)