vendor/knpuniversity/oauth2-client-bundle/src/Security/Authenticator/SocialAuthenticator.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * OAuth2 Client Bundle
  4.  * Copyright (c) KnpUniversity <http://knpuniversity.com/>
  5.  *
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * file that was distributed with this source code.
  8.  */
  9. namespace KnpU\OAuth2ClientBundle\Security\Authenticator;
  10. use KnpU\OAuth2ClientBundle\Client\OAuth2ClientInterface;
  11. use KnpU\OAuth2ClientBundle\Exception\InvalidStateException;
  12. use KnpU\OAuth2ClientBundle\Exception\MissingAuthorizationCodeException;
  13. use KnpU\OAuth2ClientBundle\Security\Exception\IdentityProviderAuthenticationException;
  14. use KnpU\OAuth2ClientBundle\Security\Exception\InvalidStateAuthenticationException;
  15. use KnpU\OAuth2ClientBundle\Security\Exception\NoAuthCodeAuthenticationException;
  16. use KnpU\OAuth2ClientBundle\Security\Helper\FinishRegistrationBehavior;
  17. use KnpU\OAuth2ClientBundle\Security\Helper\PreviousUrlHelper;
  18. use KnpU\OAuth2ClientBundle\Security\Helper\SaveAuthFailureMessage;
  19. use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
  20. use Symfony\Component\Security\Core\User\UserInterface;
  21. use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
  22. abstract class SocialAuthenticator extends AbstractGuardAuthenticator
  23. {
  24.     use FinishRegistrationBehavior;
  25.     use PreviousUrlHelper;
  26.     use SaveAuthFailureMessage;
  27.     protected function fetchAccessToken(OAuth2ClientInterface $client, array $options = [])
  28.     {
  29.         try {
  30.             return $client->getAccessToken($options);
  31.         } catch (MissingAuthorizationCodeException $e) {
  32.             throw new NoAuthCodeAuthenticationException();
  33.         } catch (IdentityProviderException $e) {
  34.             throw new IdentityProviderAuthenticationException($e);
  35.         } catch (InvalidStateException $e) {
  36.             throw new InvalidStateAuthenticationException($e);
  37.         }
  38.     }
  39.     public function checkCredentials($credentialsUserInterface $user): bool
  40.     {
  41.         // do nothing - the fact that the access token works is enough
  42.         return true;
  43.     }
  44.     public function supportsRememberMe(): bool
  45.     {
  46.         return true;
  47.     }
  48. }