Javascript 使用websocket刷新cookie中的jwt令牌
我对刷新access/jwt令牌的一般流程有点困惑。我使用socketcluster作为客户端和服务器之间的主要通信方式 初始请求(提供html)由express完成。客户端可以使用passport.js github策略通过github登录Javascript 使用websocket刷新cookie中的jwt令牌,javascript,node.js,express,cookies,passport.js,Javascript,Node.js,Express,Cookies,Passport.js,我对刷新access/jwt令牌的一般流程有点困惑。我使用socketcluster作为客户端和服务器之间的主要通信方式 初始请求(提供html)由express完成。客户端可以使用passport.js github策略通过github登录 passport.use(new githubStrategy({ clientID:'********', clientSecret:'*******', callbackURL:'http://localhost:3000/auth/git
passport.use(new githubStrategy({
clientID:'********',
clientSecret:'*******',
callbackURL:'http://localhost:3000/auth/github/callback'
},
function(accessToken,refreshToken,profile,done){
profile.token = jwt.sign({
id:profile.id,
username:profile.username
},'rush2112')
return done(null,profile)
}
))
passport的社交策略似乎使用我忽略的会话,并为客户端登录生成jwt令牌
成功登录后,我使用以下命令将jwt存储在浏览器cookie中
app.get('/auth/github',passport.authenticate('github'))
app.get('/auth/github/callback',passport.authenticate('github',{failureRedirect:'/fail'}),
function(req,res){
var text = JSON.stringify({id_token: req.user.token})
res.cookie('id_token',text,{ expires: new Date(Date.now() + 900000), httpOnly: true })
res.redirect('/')
}
)
然后,我可以使用socket.request.headers.cookie
然后我继续使用
var cookie = decodeURIComponent(socket.request.headers.cookie)
var id_token = JSON.parse(cookie.split('=')[1])
var decoded = jwt.verify(id_token.id_token,'rush2112')
我有几个问题:
您使用的是什么套接字库?注意,如果您愿意,可以从客户端更改cookie值。我正在使用socketcluster。。我已将cookies设置为仅http。。js cookie还能用吗?我想应该能用,但我没有试过。还要看看这个:但是你需要使用会话。