lib/validator.js
function(token, cb){
      try{
        // decode the token
        var _token = waterlock.jwt.decode(token, waterlock.config.jsonWebTokens.secret);

        // set the time of the request
        var _reqTime = Date.now();

        // If token is expired
        if(_token.exp <= _reqTime){
          waterlock.logger.debug('access token rejected, reason: EXPIRED');
          return cb('Your token is expired.');
        }

        // If token is early
        if(_reqTime <= _token.nbf){
          waterlock.logger.debug('access token rejected, reason: TOKEN EARLY');
          return cb('This token is early.');
        }

        // If audience doesn't match
        if(waterlock.config.jsonWebTokens.audience !== _token.aud){
          waterlock.logger.debug('access token rejected, reason: AUDIENCE');
          return cb('This token cannot be accepted for this domain.');
        }

        this.findUserFromToken(_token, cb);

      } catch(err){
        cb(err);
      }
    }
function(token, cb){
      try{
        // decode the token
        var _token = waterlock.jwt.decode(token, waterlock.config.jsonWebTokens.secret);

        // set the time of the request
        var _reqTime = Date.now();

        // If token is expired
        if(_token.exp <= _reqTime){
          waterlock.logger.debug('access token rejected, reason: EXPIRED');
          return cb('Your token is expired.');
        }

        // If token is early
        if(_reqTime <= _token.nbf){
          waterlock.logger.debug('access token rejected, reason: TOKEN EARLY');
          return cb('This token is early.');
        }

        // If audience doesn't match
        if(waterlock.config.jsonWebTokens.audience !== _token.aud){
          waterlock.logger.debug('access token rejected, reason: AUDIENCE');
          return cb('This token cannot be accepted for this domain.');
        }

        this.findUserFromToken(_token, cb);

      } catch(err){
        cb(err);
      }
    }
function ( token , cb ) { try { // decode the token var _token = waterlock . jwt . decode ( token , waterlock . config . jsonWebTokens . secret ) ; // set the time of the request var _reqTime = Date . now ( ) ; // If token is expired if ( _token . exp <= _reqTime ) { waterlock . logger . debug ( 'access token rejected, reason: EXPIRED' ) ; return cb ( 'Your token is expired.' ) ; } // If token is early if ( _reqTime <= _token . nbf ) { waterlock . logger . debug ( 'access token rejected, reason: TOKEN EARLY' ) ; return cb ( 'This token is early.' ) ; } // If audience doesn't match if ( waterlock . config . jsonWebTokens . audience !== _token . aud ) { waterlock . logger . debug ( 'access token rejected, reason: AUDIENCE' ) ; return cb ( 'This token cannot be accepted for this domain.' ) ; } this . findUserFromToken ( _token , cb ) ; } catch ( err ) { cb ( err ) ; } }
Validates a token

@param  {String}   token the token to be validated
@param  {Function} cb    called when error has occured or token is validated
Validates a token