GoogleAuthController.php in Social Auth Google 3.x
File
src/Controller/GoogleAuthController.php
View source
<?php
namespace Drupal\social_auth_google\Controller;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\social_api\Plugin\NetworkManager;
use Drupal\social_auth\Controller\OAuth2ControllerBase;
use Drupal\social_auth\SocialAuthDataHandler;
use Drupal\social_auth\User\UserAuthenticator;
use Drupal\social_auth_google\GoogleAuthManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class GoogleAuthController extends OAuth2ControllerBase {
public function __construct(MessengerInterface $messenger, NetworkManager $network_manager, UserAuthenticator $user_authenticator, GoogleAuthManager $google_manager, RequestStack $request, SocialAuthDataHandler $data_handler, RendererInterface $renderer) {
parent::__construct('Social Auth Google', 'social_auth_google', $messenger, $network_manager, $user_authenticator, $google_manager, $request, $data_handler, $renderer);
}
public static function create(ContainerInterface $container) {
return new static($container
->get('messenger'), $container
->get('plugin.network.manager'), $container
->get('social_auth.user_authenticator'), $container
->get('social_auth_google.manager'), $container
->get('request_stack'), $container
->get('social_auth.data_handler'), $container
->get('renderer'));
}
public function callback() {
$redirect = $this
->checkAuthError();
if ($redirect) {
return $redirect;
}
$profile = $this
->processCallback();
if ($profile !== NULL) {
$data = $this->userAuthenticator
->checkProviderIsAssociated($profile
->getId()) ? NULL : $this->providerManager
->getExtraDetails();
return $this->userAuthenticator
->authenticateUser($profile
->getName(), $profile
->getEmail(), $profile
->getId(), $this->providerManager
->getAccessToken(), $profile
->getAvatar(), $data);
}
return $this
->redirect('user.login');
}
}