You are here

public function OAuth2ControllerBase::__construct in Social Auth 8.2

Same name and namespace in other branches
  1. 3.x src/Controller/OAuth2ControllerBase.php \Drupal\social_auth\Controller\OAuth2ControllerBase::__construct()

SocialAuthControllerBase constructor.

Parameters

string $module: The module name.

string $plugin_id: The plugin id.

\Drupal\Core\Messenger\MessengerInterface $messenger: The messenger service.

\Drupal\social_api\Plugin\NetworkManager $network_manager: Used to get an instance of the network plugin.

\Drupal\social_auth\User\UserAuthenticator $user_authenticator: Used to manage user authentication/registration.

\Drupal\social_auth\AuthManager\OAuth2ManagerInterface $provider_manager: Used to manage authentication methods.

\Symfony\Component\HttpFoundation\RequestStack $request: Used to access GET parameters.

\Drupal\social_auth\SocialAuthDataHandler $data_handler: The Social Auth data handler.

\Drupal\Core\Render\RendererInterface $renderer: Used to handle metadata for redirection to authentication URL.

File

src/Controller/OAuth2ControllerBase.php, line 107

Class

OAuth2ControllerBase
Handle responses for Social Auth implementer controllers.

Namespace

Drupal\social_auth\Controller

Code

public function __construct($module, $plugin_id, MessengerInterface $messenger, NetworkManager $network_manager, UserAuthenticator $user_authenticator, OAuth2ManagerInterface $provider_manager, RequestStack $request, SocialAuthDataHandler $data_handler, RendererInterface $renderer = NULL) {
  $this->module = $module;
  $this->pluginId = $plugin_id;
  $this->messenger = $messenger;
  $this->networkManager = $network_manager;
  $this->userAuthenticator = $user_authenticator;
  $this->providerManager = $provider_manager;
  $this->request = $request;
  $this->dataHandler = $data_handler;
  $this->renderer = $renderer;

  /*
   * TODO: Added for backward compatibility.
   *
   * Remove after implementers have been updated.
   * @see https://www.drupal.org/project/social_auth/issues/3033444
   */
  if (!$this->renderer) {
    $this->renderer = \Drupal::service('renderer');
  }

  // Sets the plugin id in user authenticator.
  $this->userAuthenticator
    ->setPluginId($plugin_id);

  // Sets the session prefix.
  $this->dataHandler
    ->setSessionPrefix($plugin_id);

  // Sets the session keys to nullify if user could not logged in.
  $this->userAuthenticator
    ->setSessionKeysToNullify([
    'access_token',
    'oauth2state',
  ]);
}