/** * @param UserProviderInterface $userProvider * @param Token $token * * @throws AuthenticationException * @throws AuthenticationServiceException * * @return UserInterface */ protected function retrieveUser(UserProviderInterface $userProvider, Token $token) { $parts = $this->tokenManager->getEncoder()->decodeHash($token->getHash()); if (count($parts) !== 4) { throw new AuthenticationException('The hash is invalid.'); } list($class, $username, $expires, $hash) = $parts; if (false === ($username = base64_decode($username, true))) { throw new AuthenticationException('$username contains a character from outside the base64 alphabet.'); } try { $user = $userProvider->loadUserByUsername($username); } catch (\Exception $e) { throw new AuthenticationServiceException($e->getMessage(), 0, $e); } if (!$user instanceof UserInterface) { throw new AuthenticationServiceException('The user provider must return a UserInterface object.'); } return $user; }
/** * @param Token $token * * @return array */ protected function getTokenData(Token $token) { return ['id' => $token->getId(), 'expires' => $token->getExpiresAt()->format(\DateTime::ISO8601)]; }