/**
  * Loads the user for the given username.
  *
  * This method must throw UsernameNotFoundException if the user is not
  * found.
  *
  * @param string $username The username
  *
  * @return UserInterface
  *
  * @throws UsernameNotFoundException if the user is not found
  */
 public function loadUserByUsername($username)
 {
     $user = $this->userRepository->findOneBy(['username' => $username]);
     if (!$user) {
         throw new UsernameNotFoundException($this->translator->trans('Username %username% does not exist!', ['%username%' => $username]));
     }
     return $user;
 }
 /**
  * Return a UserInterface object based on the credentials.
  *
  * The *credentials* are the return value from getCredentials()
  *
  * You may throw an AuthenticationException if you wish. If you return
  * null, then a UsernameNotFoundException is thrown for you.
  *
  * @param mixed $credentials
  * @param UserProviderInterface $userProvider
  *
  * @throws AuthenticationException
  *
  * @return UserInterface|null
  */
 public function getUser($credentials, UserProviderInterface $userProvider)
 {
     $apiKey = $credentials['token'];
     return $this->userRepository->findOneBy(['apiKey' => $apiKey]);
 }