You are here

class GoogleAuth in Social Auth Google 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Network/GoogleAuth.php \Drupal\social_auth_google\Plugin\Network\GoogleAuth
  2. 8 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

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

Namespace

Drupal\social_auth_google\Plugin\Network
View source
class GoogleAuth extends NetworkBase implements GoogleAuthInterface {

  /**
   * Sets the underlying SDK library.
   *
   * @return \League\OAuth2\Client\Provider\Google|false
   *   The initialized 3rd party library instance.
   *   False if library could not be initialized.
   *
   * @throws \Drupal\social_api\SocialApiException
   *   If the SDK library does not exist.
   */
  protected function initSdk() {
    $class_name = '\\League\\OAuth2\\Client\\Provider\\Google';
    if (!class_exists($class_name)) {
      throw new SocialApiException(sprintf('The Google library for PHP League OAuth2 not found. Class: %s.', $class_name));
    }

    /** @var \Drupal\social_auth_google\Settings\GoogleAuthSettings $settings */
    $settings = $this->settings;
    if ($this
      ->validateConfig($settings)) {

      // All these settings are mandatory.
      $league_settings = [
        'clientId' => $settings
          ->getClientId(),
        'clientSecret' => $settings
          ->getClientSecret(),
        'redirectUri' => Url::fromRoute('social_auth_google.callback')
          ->setAbsolute()
          ->toString(),
        'accessType' => 'offline',
        'verify' => FALSE,
        'hostedDomain' => $settings
          ->getRestrictedDomain() == '' ? NULL : $settings
          ->getRestrictedDomain(),
      ];

      // Proxy configuration data for outward proxy.
      $config = $this->siteSettings
        ->get('http_client_config');
      if (!empty($config['proxy']['http'])) {
        $league_settings['proxy'] = $config['proxy']['http'];
      }
      return new Google($league_settings);
    }
    return FALSE;
  }

  /**
   * 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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
GoogleAuth::initSdk protected function Sets the underlying SDK library. Overrides NetworkBase::initSdk
GoogleAuth::validateConfig protected function Checks that module is configured.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
NetworkBase::$entityTypeManager protected property The entity type manager.
NetworkBase::$loggerFactory protected property The logger factory.
NetworkBase::$sdk protected property The SDK client.
NetworkBase::$settings protected property The implementer/plugin settings.
NetworkBase::$siteSettings protected property The global site settings.
NetworkBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
NetworkBase::getSdk public function Gets the underlying SDK library. Overrides NetworkInterface::getSdk
NetworkBase::init protected function Initialize the plugin.
NetworkBase::__construct public function Instantiates a NetworkBase object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.