Exemple #1
0
 /**
  * Add the token (jti claim) to the blacklist
  *
  * @param  \Tymon\JWTAuth\Payload  $payload
  * @return boolean
  */
 public function add(Payload $payload)
 {
     $exp = Utils::timestamp($payload['exp']);
     // there is no need to add the token to the blacklist
     // if the token has already expired
     if ($exp->isPast()) {
         return false;
     }
     // add a minute to abate potential overlap
     $minutes = $exp->diffInMinutes(Utils::now()->subMinute());
     $this->storage->add($payload['jti'], [], $minutes);
     return true;
 }
Exemple #2
0
 /**
  * Add the token (jti claim) to the blacklist.
  *
  * @param  \Tymon\JWTAuth\Payload  $payload
  * @return bool
  */
 public function add(Payload $payload)
 {
     $exp = Utils::timestamp($payload['exp']);
     $refreshExp = Utils::timestamp($payload['iat'])->addMinutes($this->refreshTTL);
     // there is no need to add the token to the blacklist
     // if the token has already expired AND the refresh_ttl
     // has gone by
     if ($exp->isPast() && $refreshExp->isPast()) {
         return false;
     }
     // Set the cache entry's lifetime to be equal to the amount
     // of refreshable time it has remaining (which is the larger
     // of `exp` and `iat+refresh_ttl`), rounded up a minute
     $cacheLifetime = $exp->max($refreshExp)->addMinute()->diffInMinutes();
     $this->storage->add($payload['jti'], [], $cacheLifetime);
     return true;
 }