GoogleAuth.php in Social Auth Google 8
File
src/Plugin/Network/GoogleAuth.php
View source
<?php
namespace Drupal\social_auth_google\Plugin\Network;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Render\MetadataBubblingUrlGenerator;
use Drupal\social_api\SocialApiException;
use Drupal\social_auth\Plugin\Network\SocialAuthNetwork;
use Symfony\Component\DependencyInjection\ContainerInterface;
class GoogleAuth extends SocialAuthNetwork {
protected $urlGenerator;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('url_generator'), $configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('config.factory'));
}
public function __construct(MetadataBubblingUrlGenerator $url_generator, array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $config_factory);
$this->urlGenerator = $url_generator;
}
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));
}
$settings = $this->settings;
$redirect_uri = $this->urlGenerator
->generateFromRoute('social_auth_google.callback', [], [
'absolute' => TRUE,
]);
$client = new \Google_Client();
$client
->setClientId($settings
->getClientId());
$client
->setClientSecret($settings
->getClientSecret());
$client
->setHostedDomain($settings
->getRestrictedDomain());
$client
->setRedirectUri($redirect_uri);
return $client;
}
}
Classes
Name |
Description |
GoogleAuth |
Defines Social Auth Google Network Plugin. |