几分钟的闲置应用程序后,JWT在Android上取消认证

时间:2017-03-20 11:04:53

标签: android node.js jwt

我有一个nodejs服务器,使用快速JWT连接到Android客户端。 JWT的财产是expiresInMinutes: 60*5*100

但是,如果我在后台暂停应用程序闲置超过几秒钟,打开其他应用程序,然后从后台重新打开我的应用程序,该应用程序无法正常打开,服务器显示JWT错误,跟踪跟踪

error: Server Error:
error: Error
    at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/lib/index.js:109:53
    at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/jsonwebtoken/index.js:98:18
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickDomainCallback (internal/process/next_tick.js:122:9) { Error
    at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/lib/index.js:109:53
    at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/jsonwebtoken/index.js:98:18
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickDomainCallback (internal/process/next_tick.js:122:9)
  name: 'UnauthorizedError',
  message: 'jwt malformed',
  code: 'invalid_token',
  status: 401,
  inner: 
   { Error
       at Object.module.exports.verify (/home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/jsonwebtoken/index.js:115:17)
       at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/lib/index.js:108:11
       at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:251:17
       at done (/home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:132:19)
       at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:32:16
       at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:248:21
       at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:572:34
       at DEFAULT_REVOKED_FUNCTION (/home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/lib/index.js:6:61)
       at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/lib/index.js:97:9
       at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:567:21
       at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:246:17
       at /home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:122:13
       at _each (/home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:46:13)
       at async.each (/home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:121:9)
       at _asyncMap (/home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:245:13)
       at Object.map (/home/ubuntu/marrily-server/marrily-dev/marrily-api/marrily/node_modules/express-jwt/node_modules/async/lib/async.js:216:23) name: 'JsonWebTokenError', message: 'jwt malformed' } }

如何解决这个问题?

修改

发出令牌的代码是:

var jwt = require('jsonwebtoken');

req.body.id = user[0].id;
try{
    var token = jwt.sign(user[0], 'SomeSuperSecret', {expiresInMinutes: 60*5*100});
}catch(err){
    res.json({msg:'jwt error'});
}

验证令牌的代码位于config/http.js

module.exports = {
  http:{
    customMiddleware: function(app){
      app.use(expressJwt({secret: 'SomeSuperSecret'}).unless({path: [
          //list of URLs
      ]}));
    }
  }
}

0 个答案:

没有答案