You are here

public function GoogleAuth::initSdk in Social Auth Google 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth::initSdk()
  2. 3.x src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth::initSdk()

File

src/Plugin/Network/GoogleAuth.php, line 74

Class

GoogleAuth
Defines Social Auth Google Network Plugin.

Namespace

Drupal\social_auth_google\Plugin\Network

Code

public function initSdk() {
  $class_name = '\\Google_Client';
  if (!class_exists($class_name)) {
    throw new SocialApiException(sprintf('The PHP SDK for Google Services could not be found. Class: %s.', $class_name));
  }

  /* @var \Drupal\social_auth_google\Settings\GoogleAuthSettings $settings */
  $settings = $this->settings;

  // Gets the absolute url of the callback.
  $redirect_uri = $this->urlGenerator
    ->generateFromRoute('social_auth_google.callback', [], [
    'absolute' => TRUE,
  ]);

  // Creates a and sets data to Google_Client object.
  $client = new \Google_Client();
  $client
    ->setClientId($settings
    ->getClientId());
  $client
    ->setClientSecret($settings
    ->getClientSecret());
  $client
    ->setHostedDomain($settings
    ->getRestrictedDomain());
  $client
    ->setRedirectUri($redirect_uri);
  return $client;
}