Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function fetchToken(Request $request)
 {
     $hash = $this->extractHash($request);
     $partials = $this->getTokenPartials($hash);
     if (empty($partials)) {
         return null;
     }
     list($selector, $series, $value) = $partials;
     try {
         if (!($authToken = $this->tokenSource()->findBySelector($selector))) {
             return null;
         }
         if ($authToken->isExpired()) {
             $this->tokenSource()->deleteToken($authToken);
             return null;
         }
         //If series is incorrect - skip record (token is invalid)
         if (strcasecmp($authToken->getSeries(), $series) !== 0) {
             return null;
         }
         //If hash is incorrect - record should be deleted because series is compromised
         if (!$this->hashes->hashEquals($value, $authToken->getHashValue())) {
             $this->tokenSource()->deleteToken($authToken);
             return null;
         }
         return $authToken;
     } catch (UndefinedTokenException $e) {
         return null;
     }
 }