You are here

public function GoogleAuthController::getProfile in Open Social 8.9

Same name and namespace in other branches
  1. 8 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::getProfile()
  2. 8.2 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::getProfile()
  3. 8.3 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::getProfile()
  4. 8.4 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::getProfile()
  5. 8.5 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::getProfile()
  6. 8.6 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::getProfile()
  7. 8.7 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::getProfile()
  8. 8.8 modules/custom/social_auth_google/src/Controller/GoogleAuthController.php \Drupal\social_auth_google\Controller\GoogleAuthController::getProfile()

Loads access token, then loads profile.

Parameters

string $type: The type.

Return value

object Returns an object.

2 calls to GoogleAuthController::getProfile()
GoogleAuthController::userLoginCallback in modules/custom/social_auth_google/src/Controller/GoogleAuthController.php
Authorizes the user after redirect from Google.
GoogleAuthController::userRegisterCallback in modules/custom/social_auth_google/src/Controller/GoogleAuthController.php
Registers the new account after redirect from Google.

File

modules/custom/social_auth_google/src/Controller/GoogleAuthController.php, line 230

Class

GoogleAuthController
Class GoogleAuthController.

Namespace

Drupal\social_auth_google\Controller

Code

public function getProfile($type) {

  // Get the OAuth token from Google.
  if (!($access_token = $this->authManager
    ->getAccessToken($type))) {
    drupal_set_message($this
      ->t('@network login failed. Token is not valid.', [
      '@network' => $this
        ->t('Google'),
    ]), 'error');
    return $this
      ->redirect('user.' . $type);
  }

  // Get user's Google profile from Google API.
  if (!($profile = $this->authManager
    ->getProfile()) || !$profile
    ->getId()) {
    drupal_set_message($this
      ->t('@network login failed, could not load @network profile. Contact the site administrator.', [
      '@network' => $this
        ->t('Google'),
    ]), 'error');
    return $this
      ->redirect('user.' . $type);
  }
  $this->accessToken = $access_token;
  return $profile;
}