public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     $jwt = $token->getCredentials();
     $token = $this->userProvider->getDecodedToken($jwt);
     $clientKey = $token->iss;
     if (!$clientKey) {
         throw new AuthenticationException(sprintf('API Key "%s" does not exist.', $jwt));
     }
     /** @var Tenant $user */
     $user = $this->userProvider->loadUserByUsername($clientKey);
     $user->setUsername($token->sub);
     return new PreAuthenticatedToken($user, $jwt, $providerKey, $user->getRoles());
 }
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     $jwt = $token->getCredentials();
     $token = $this->userProvider->getDecodedToken($jwt);
     $clientKey = $token->iss;
     if (!$clientKey) {
         throw new AuthenticationException(sprintf('API Key "%s" does not exist.', $jwt));
     }
     /** @var Tenant $user */
     $user = $this->userProvider->loadUserByUsername($clientKey);
     if (property_exists($token, "sub")) {
         // for some reasons, when webhooks are called - field sub is undefined
         $user->setUsername($token->sub);
     }
     return new PreAuthenticatedToken($user, $jwt, $providerKey, $user->getRoles());
 }