Setting expiry using koa-jwt
<p>I'm attempting to use the json web token <a href="https://github.com/koajs/jwt" rel="nofollow">koa-jwt middleware</a> for a koa-based node app I'm writing. I'd like to set the expiry of the web-token's payload and I've noticed that using the standard implementation produces an expiry date in the payload that is two months later. This implementation looks like the following: </p>

<pre><code>var koa = require('koa');
var jwt = require('koa-jwt');

var app = koa();

...

// This is the jwt line in question...
app.use(jwt({ secret: 'shared-secret' }));

...
</code></pre>

<p>What I'd like to do is control this so that I can set it to be 1 week, 1 day, 15 minutes, whatever. I've tried a number of variations such as:</p>

<pre><code>app.use(jwt({ secret: 'shared-secret', exp: 30 }));
app.use(jwt({ secret: 'shared-secret', expires: 30 }));
</code></pre>

<p>...and many others, but so far nothing has worked and the documentation is very light in this regard. Any insights as to how this is done would be appreciated. </p>

<p><strong>Feb 26 Update</strong>
Thanks to clemkoa I found my answer - turns out I was doing exactly what I needed to with the "exp" attribute the whole time. During login a successful authentication of user returns this: </p>

<pre><code>ctx.body = {success: true, token: user.generateJWT()};
</code></pre>

<p>Where user.generateJWT() is a function call in the User Mongoose schema. The function looks like this: </p>

<pre><code>UserSchema.methods.generateJWT = function() {
  // set jwt expiration
  var today = new Date();
  var exp = new Date(today);
  exp.setDate(today.getDate() + 1);

  return jwt.sign({
    _id: this._id,
    username: this.username,
    exp: parseInt(exp.getTime() / 1000)
  }, config.jwtSecret);
};
</code></pre>

<p>Note the inclusion of the "exp" attribute. That is the line in question.</p>