如何在express.js / passport-http-bearer中撤销express-jwt令牌

时间:2015-07-09 10:28:19

标签: express jwt express-jwt

这是我的路由器:

expressJwt    = require('express-jwt')
router.post '/signin'      , controller.signUp
router.get  '/signout/:id' , expressJwt(secret:secretToken,  isRevoked: isRevokedCallback), controller.signOut

这是我的signOut端点:

exports.signOut = (req, res) ->
  console.log res.user

我需要将哪些内容放入我的端点以撤消令牌。

我尝试将此功能放入路由器:

isRevokedCallback = (req, payload, done) ->
  for key, value of payload
    console.log(key + ' ' + value)
  # The below part does not work. Also I don't know what data should refer to
  issuer = payload.iss
  tokenId = payload.jti
  data.getRevokedToken issuer, tokenId, (err, token) ->
    if err
      return done(err)
    done null, ! !token
  return

列表理解确实会退出:

iat 1436437563
exp 1436653563

我的终端中还有一个用户对象已注销:

user [object Object]

现在如何将各个部分放在一起并撤销JWT令牌,以便那个令牌的用户不再能够使用该令牌登录(或者可以立即使其过期)?

以下是我的用户对象的一些示例控制台日志:

{ user: 
   { __v: 0,
     _id: '559e6aad50cdf686db31ea55',
     local: 
      { password: '$2a$08$YBvzOWADlw9tZCDh3aG/j.gV.Tbaesk3pLbbiHL/lkGaC08bSbGmy',
        email: 'dieter@mustermann.de' } },
  iat: 1436445357,
  exp: 1436661357 }
GET /user/signout/559e6aad50cdf686db31ea55 401 2.530 ms - 12
ERROR:Error: expected 200 "OK", got 401 "Unauthorized"
    1) should sign out via passport.js

0 个答案:

没有答案