vendor/pimcore/customer-management-framework-bundle/src/Security/UserProvider/OAuthAwareUserProvider.php line 95

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Commercial License (PCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  14.  */
  15. namespace CustomerManagementFrameworkBundle\Security\UserProvider;
  16. use CustomerManagementFrameworkBundle\Model\CustomerInterface;
  17. use CustomerManagementFrameworkBundle\Security\OAuth\Exception\AccountNotLinkedException;
  18. use CustomerManagementFrameworkBundle\Security\SsoIdentity\SsoIdentityServiceInterface;
  19. use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
  20. use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthAwareUserProviderInterface;
  21. use Symfony\Component\Security\Core\User\UserInterface;
  22. use Symfony\Component\Security\Core\User\UserProviderInterface;
  23. /**
  24.  * @deprecated
  25.  *
  26.  * Decorates a user provider and adds OAUth provider capabilities
  27.  */
  28. class OAuthAwareUserProvider implements UserProviderInterfaceOAuthAwareUserProviderInterface
  29. {
  30.     /**
  31.      * @var UserProviderInterface
  32.      */
  33.     private $userProvider;
  34.     /**
  35.      * @var SsoIdentityServiceInterface
  36.      */
  37.     private $ssoIdentityService;
  38.     public function __construct(
  39.         UserProviderInterface $userProvider,
  40.         SsoIdentityServiceInterface $ssoIdentityService
  41.     ) {
  42.         $this->userProvider $userProvider;
  43.         $this->ssoIdentityService $ssoIdentityService;
  44.     }
  45.     public function loadUserByOAuthUserResponse(UserResponseInterface $response)
  46.     {
  47.         $provider $response->getResourceOwner()->getName();
  48.         $username = (string)$response->getUsername();
  49.         /** @var CustomerInterface|UserInterface|null $user */
  50.         $user $this->ssoIdentityService->getCustomerBySsoIdentity(
  51.             $provider,
  52.             $username
  53.         );
  54.         if (is_null($user) || '' === $username) {
  55.             // the AccountNotLinkedException will allow the frontend to proceed to registration
  56.             // and to fetch user data from the OAuth account
  57.             $exception = new AccountNotLinkedException(sprintf(
  58.                 'No customer was found for user "%s" on provider "%s"',
  59.                 $username,
  60.                 $provider
  61.             ));
  62.             if (method_exists($exception'setUsername')) {
  63.                 $exception->setUsername($username);
  64.             }
  65.             throw $exception;
  66.         }
  67.         return $user;
  68.     }
  69.     public function loadUserByUsername($username)
  70.     {
  71.         return $this->userProvider->loadUserByUsername($username);
  72.     }
  73.     public function refreshUser(UserInterface $user)
  74.     {
  75.         return $this->userProvider->refreshUser($user);
  76.     }
  77.     public function supportsClass($class)
  78.     {
  79.         return $this->userProvider->supportsClass($class);
  80.     }
  81. }