vendor/knpuniversity/oauth2-client-bundle/src/Security/Authenticator/OAuth2Authenticator.php line 31

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\Http\Authenticator\AbstractAuthenticator;
  21. abstract class OAuth2Authenticator extends AbstractAuthenticator
  22. {
  23.     use FinishRegistrationBehavior;
  24.     use PreviousUrlHelper;
  25.     use SaveAuthFailureMessage;
  26.     protected function fetchAccessToken(OAuth2ClientInterface $client, array $options = [])
  27.     {
  28.         try {
  29.             return $client->getAccessToken($options);
  30.         } catch (MissingAuthorizationCodeException $e) {
  31.             throw new NoAuthCodeAuthenticationException();
  32.         } catch (IdentityProviderException $e) {
  33.             throw new IdentityProviderAuthenticationException($e);
  34.         } catch (InvalidStateException $e) {
  35.             throw new InvalidStateAuthenticationException($e);
  36.         }
  37.     }
  38. }