使用websocket在cookie中刷新一个jwt标记

我对刷新访问/ jwt令牌的一般stream程感到困惑。 我使用socketcluster作为客户端和服务器之间的主要通信方式。

最初的请求(服务的HTML)是由快递。 客户端可以通过github使用passport.js github策略login

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) } )) 

带护照的社交策略似乎使用我忽略的会话,并为客户端login生成一个jwt令牌。

成功login,我使用下面的浏览器cookie中存储jwt

  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从套接字访问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') 

我有一些问题 :

  1. 上述方法是有效的还是我忽略了任何东西?
  2. 我如何刷新标记? 我是否刷新cookie本身或只是cookie中存在的id_token。
  3. 无论如何,我可以重置/设置快递外的cookie? 可能通过websockets本身?