You are here

class GoogleAuth in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/custom/social_auth_google/src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth
  2. 8 modules/custom/social_auth_google/src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth
  3. 8.2 modules/custom/social_auth_google/src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth
  4. 8.3 modules/custom/social_auth_google/src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth
  5. 8.4 modules/custom/social_auth_google/src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth
  6. 8.5 modules/custom/social_auth_google/src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth
  7. 8.6 modules/custom/social_auth_google/src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth
  8. 8.8 modules/custom/social_auth_google/src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth

Defines a Network Plugin for Social Auth Google.

@package Drupal\social_auth_google\Plugin\Network

Plugin annotation


@Network(
  id = "social_auth_google",
  social_network = "Google",
  type = "social_auth",
  handlers = {
    "settings": {
      "class": "\Drupal\social_auth_google\Settings\GoogleAuthSettings",
      "config_id": "social_auth_google.settings"
    }
  }
)

Hierarchy

Expanded class hierarchy of GoogleAuth

File

modules/custom/social_auth_google/src/Plugin/Network/GoogleAuth.php, line 26

Namespace

Drupal\social_auth_google\Plugin\Network
View source
class GoogleAuth extends SocialAuthNetwork {

  /**
   * Returns an instance of sdk.
   *
   * @return mixed
   *   Returns a new Google Client instance or FALSE if the config was
   *   incorrect.
   *
   * @throws \Drupal\social_api\SocialApiException
   */
  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));
    }
    if (!$this
      ->validateConfig($this->settings)) {
      return FALSE;
    }
    $client = new $class_name();
    $client
      ->setClientId($this->settings
      ->getClientId());
    $client
      ->setClientSecret($this->settings
      ->getClientSecret());
    return $client;
  }

  /**
   * Returns status of social network.
   *
   * @return bool
   *   The status of the social network.
   */
  public function isActive() {
    return (bool) $this->settings
      ->isActive();
  }

  /**
   * Checks that module is configured.
   *
   * @param \Drupal\social_auth_google\Settings\GoogleAuthSettings $settings
   *   The Google auth settings.
   *
   * @return bool
   *   True if module is configured, False otherwise.
   */
  protected function validateConfig(GoogleAuthSettings $settings) {
    $client_id = $settings
      ->getClientId();
    $client_secret = $settings
      ->getClientSecret();
    if (!$client_id || !$client_secret) {
      $this->loggerFactory
        ->get('social_auth_google')
        ->error('Define Client ID and Client Secret on module settings.');
      return FALSE;
    }
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function getSocialNetworkKey() {
    return $this->settings
      ->getSocialNetworkKey();
  }

  /**
   * Returns an instance of storage that handles data.
   *
   * @return object
   *   An instance of the storage that handles the data.
   */
  public function getDataHandler() {
    $data_handler = \Drupal::service('social_auth_extra.session_persistent_data_handler');
    $data_handler
      ->setPrefix('social_auth_google_');
    return $data_handler;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GoogleAuth::getDataHandler public function Returns an instance of storage that handles data.
GoogleAuth::getSocialNetworkKey public function
GoogleAuth::initSdk public function Returns an instance of sdk.
GoogleAuth::isActive public function Returns status of social network.
GoogleAuth::validateConfig protected function Checks that module is configured.