You are here

public function GoogleAuthController::callback in Social Auth Google 3.x

Same name and namespace in other branches
  1. 8.2 src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::callback()
  2. 8 src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::callback()

Response for path 'user/login/google/callback'.

Google returns the user here after user has authenticated.

1 string reference to 'GoogleAuthController::callback'
social_auth_google.routing.yml in ./social_auth_google.routing.yml
social_auth_google.routing.yml

File

src/Controller/GoogleAuthController.php, line 71

Class

GoogleAuthController
Returns responses for Social Auth Google module routes.

Namespace

Drupal\social_auth_google\Controller

Code

public function callback() {

  // Checks if there was an authentication error.
  $redirect = $this
    ->checkAuthError();
  if ($redirect) {
    return $redirect;
  }

  /** @var \League\OAuth2\Client\Provider\GoogleUser|null $profile */
  $profile = $this
    ->processCallback();

  // If authentication was successful.
  if ($profile !== NULL) {

    // Gets (or not) extra initial data.
    $data = $this->userAuthenticator
      ->checkProviderIsAssociated($profile
      ->getId()) ? NULL : $this->providerManager
      ->getExtraDetails();
    return $this->userAuthenticator
      ->authenticateUser($profile
      ->getName(), $profile
      ->getEmail(), $profile
      ->getId(), $this->providerManager
      ->getAccessToken(), $profile
      ->getAvatar(), $data);
  }
  return $this
    ->redirect('user.login');
}