FacebookAuthController.php in Social Auth Facebook 3.x
File
src/Controller/FacebookAuthController.php
View source
<?php
namespace Drupal\social_auth_facebook\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_facebook\FacebookAuthManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class FacebookAuthController extends OAuth2ControllerBase {
public function __construct(MessengerInterface $messenger, NetworkManager $network_manager, UserAuthenticator $user_authenticator, FacebookAuthManager $facebook_manager, RequestStack $request, SocialAuthDataHandler $data_handler, RendererInterface $renderer) {
parent::__construct('Social Auth Facebook', 'social_auth_facebook', $messenger, $network_manager, $user_authenticator, $facebook_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_facebook.manager'), $container
->get('request_stack'), $container
->get('social_auth.data_handler'), $container
->get('renderer'));
}
public function callback() {
$redirect = $this
->checkAuthError('error_code');
if ($redirect) {
return $redirect;
}
$profile = $this
->processCallback();
if ($profile) {
if (!$profile
->getEmail()) {
$this->messenger
->addError($this
->t('Facebook authentication failed. This site requires permission to get your email address.'));
return $this
->redirect('user.login');
}
$data = $this->userAuthenticator
->checkProviderIsAssociated($profile
->getId()) ? NULL : $this->providerManager
->getExtraDetails();
return $this->userAuthenticator
->authenticateUser($profile
->getName(), $profile
->getEmail(), $profile
->getId(), $this->providerManager
->getAccessToken(), $profile
->getPictureUrl(), $data);
}
return $this
->redirect('user.login');
}
}