lib/utils.js
function(req, res, user) {
    var jsonWebTokens = waterlock.config.jsonWebTokens || {};
    var expiryUnit = (jsonWebTokens.expiry && jsonWebTokens.expiry.unit) || 'days';
    var expiryLength = (jsonWebTokens.expiry && jsonWebTokens.expiry.length) || 7;
    var expires = moment().add(expiryLength, expiryUnit).valueOf();
    var issued = Date.now();
    user = user || req.session.user;

    var token = jwt.encode({
      iss: user.id + '|' + req.remoteAddress,
      sub: jsonWebTokens.subject,
      aud: jsonWebTokens.audience,
      exp: expires,
      nbf: issued,
      iat: issued,
      jti: uuid.v1()
    }, jsonWebTokens.secret);

    return {
      token: token,
      expires: expires
    };
  }
function(req, res, user) {
    var jsonWebTokens = waterlock.config.jsonWebTokens || {};
    var expiryUnit = (jsonWebTokens.expiry && jsonWebTokens.expiry.unit) || 'days';
    var expiryLength = (jsonWebTokens.expiry && jsonWebTokens.expiry.length) || 7;
    var expires = moment().add(expiryLength, expiryUnit).valueOf();
    var issued = Date.now();
    user = user || req.session.user;

    var token = jwt.encode({
      iss: user.id + '|' + req.remoteAddress,
      sub: jsonWebTokens.subject,
      aud: jsonWebTokens.audience,
      exp: expires,
      nbf: issued,
      iat: issued,
      jti: uuid.v1()
    }, jsonWebTokens.secret);

    return {
      token: token,
      expires: expires
    };
  }
function ( req , res , user ) { var jsonWebTokens = waterlock . config . jsonWebTokens || { } ; var expiryUnit = ( jsonWebTokens . expiry && jsonWebTokens . expiry . unit ) || 'days' ; var expiryLength = ( jsonWebTokens . expiry && jsonWebTokens . expiry . length ) || 7 ; var expires = moment ( ) . add ( expiryLength , expiryUnit ) . valueOf ( ) ; var issued = Date . now ( ) ; user = user || req . session . user ; var token = jwt . encode ( { iss : user . id + '|' + req . remoteAddress , sub : jsonWebTokens . subject , aud : jsonWebTokens . audience , exp : expires , nbf : issued , iat : issued , jti : uuid . v1 ( ) } , jsonWebTokens . secret ) ; return { token : token , expires : expires } ; }
Creates a new JWT token

@param  {Integer} req
@param  {Object} res
@param  {Object} user   the user model
@return {Object}       the created jwt token.
@api public
Creates a new JWT token