/**
  * {@inheritdoc}
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     try {
         $login = $this->userAppClient->user->login(array("login" => $token->getUsername(), "password" => $token->getCredentials()));
         // Load user from provider based on id
         $user = $userProvider->loadUserByLoginInfo($login);
     } catch (ServiceException $exception) {
         if ($exception->getErrorCode() == 'INVALID_ARGUMENT_LOGIN' || $exception->getErrorCode() == 'INVALID_ARGUMENT_PASSWORD') {
             throw new AuthenticationException('Invalid username or password');
         }
         if ($exception->getErrorCode() == 'INVALID_ARGUMENT_APP_ID') {
             throw new AuthenticationException('Invalid app ID');
         }
     }
     return new UserAppToken($user, $user->getToken(), $providerKey, $user->getRoles());
 }