You are here

class OpenIDConnectSession in OpenID Connect / OAuth client 8

Same name and namespace in other branches
  1. 2.x src/OpenIDConnectSession.php \Drupal\openid_connect\OpenIDConnectSession

Session service of the OpenID Connect module.

Hierarchy

Expanded class hierarchy of OpenIDConnectSession

3 files declare their use of OpenIDConnectSession
OpenIDConnectAccountsForm.php in src/Form/OpenIDConnectAccountsForm.php
OpenIDConnectLoginForm.php in src/Form/OpenIDConnectLoginForm.php
OpenIdConnectSessionTest.php in tests/src/Unit/OpenIdConnectSessionTest.php
1 string reference to 'OpenIDConnectSession'
openid_connect.services.yml in ./openid_connect.services.yml
openid_connect.services.yml
1 service uses OpenIDConnectSession
openid_connect.session in ./openid_connect.services.yml
Drupal\openid_connect\OpenIDConnectSession

File

src/OpenIDConnectSession.php, line 11

Namespace

Drupal\openid_connect
View source
class OpenIDConnectSession {

  /**
   * The current path.
   *
   * @var \Drupal\Core\Path\CurrentPathStack
   */
  protected $currentPath;

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * Construct an instance of the OpenID Connect session service.
   *
   * @param \Drupal\Core\Path\CurrentPathStack $current_path
   *   The current path.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   */
  public function __construct(CurrentPathStack $current_path, RequestStack $request_stack) {
    $this->currentPath = $current_path;
    $this->requestStack = $request_stack;
  }

  /**
   * Save the current path in the session, for redirecting after authorization.
   *
   * @todo Evaluate, whether we can now use the user.private_tempstore instead
   *   of the global $_SESSION variable, as https://www.drupal.org/node/2743931
   *   has been applied to 8.5+ core.
   */
  public function saveDestination() {
    $current_path = $this->currentPath
      ->getPath();
    $path = $current_path == '/user/login' ? '/user' : $current_path;

    // The destination could contain query parameters. Ensure that they are
    // preserved.
    $query = $this->requestStack
      ->getCurrentRequest()
      ->getQueryString();
    $_SESSION['openid_connect_destination'] = [
      $path,
      [
        'query' => $query,
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OpenIDConnectSession::$currentPath protected property The current path.
OpenIDConnectSession::$requestStack protected property The request stack.
OpenIDConnectSession::saveDestination public function Save the current path in the session, for redirecting after authorization.
OpenIDConnectSession::__construct public function Construct an instance of the OpenID Connect session service.