将护照openID-stategy与智威汤逊结合在一起
使用openID( passport-steam )尝试使用passport.js进行身份validation,然后使用令牌(JWT)而不是会话时,我遇到了问题。
我目前的代码如下所示:
app.post('/auth/steam', passport.authenticate('steam')); app.get('/auth/steam/return', passport.authenticate('steam', { failureRedirect: '/', session: false }), function(req, res) { var token = jwt.encode({ useridentifier: req.user.identifier}, tokenSecret); res.redirect('/'); });
但是,我遇到的问题是:我应该如何将令牌传回客户端? 由于这是一个从Steam网站回来后运行的GET请求,我不能用简单的答复
res.json(token)
就像我见过的人们和JWT一起使用本地策略一样。
我设法解决的唯一解决scheme就是使用包含令牌的会话(例如connect-flash),并在将其redirect到“/”后通过REST API与客户端进行通信,但是使用JWT是为了避免使用会话,不是吗?
经过多天的思考而没有得到任何地方,我设法找出另一种方法来解决它,使用cookie。
我发现关于自定义callback,通行证提供,我可以设置响应的标题,所以我重新定向之前设置一个这样的:
res.cookie('token', token, { httpOnly: true });
(不安全,因为我只在本地服务器上testing)
这就是现在整个代码的样子:
app.get('/auth/steam', passport.authenticate('steam')); app.get('/auth/steam/return', function(req, res, next) { passport.authenticate('steam', function(err, user, info){ var payload = { user: user.identifier }; var token = jwt.sign(payload, "thisisnotthesecretiactuallyuse", {expiresIn : 60*60*24}); res.cookie('token', token, { httpOnly: true /* TODO: Set secure: true */ }); res.redirect('/'); })(req, res, next) });
- 将令牌传递给我的Angular 4应用程序的优雅方式是什么?
- 如何使用访问令牌在通过twitter.js护照login后validation用户
- 如何debugging护照
- Firebase admin.auth.createUser错误(nodejs + Typescript + firebase-admin)
- Firebase身份validationID令牌具有不正确的“审核”声明
- 在跨域中节点js身份validation
- nodejs HTTP摘要authentication不起作用
- Facebook或Twitterauthentication与iPhone客户端和node.js服务器
- Passport-js如何创build自定义策略