class SessionStore in Auth0 Single Sign On 8.2
This class provides a layer to persist user access using PHP Sessions.
@author Auth0
Hierarchy
- class \Auth0\SDK\Store\SessionStore implements StoreInterface
Expanded class hierarchy of SessionStore
5 files declare their use of SessionStore
- Auth0.php in vendor/
auth0/ auth0-php/ src/ Auth0.php - AuthController.php in src/
Controller/ AuthController.php - Contains \Drupal\auth0\Controller\AuthController.
- Oauth2Client.php in vendor/
auth0/ auth0-php/ src/ API/ Oauth2Client.php - SessionStateHandlerTest.php in vendor/
auth0/ auth0-php/ tests/ API/ Helpers/ State/ SessionStateHandlerTest.php - SessionStoreTest.php in vendor/
auth0/ auth0-php/ tests/ Store/ SessionStoreTest.php
File
- vendor/
auth0/ auth0-php/ src/ Store/ SessionStore.php, line 10
Namespace
Auth0\SDK\StoreView source
class SessionStore implements StoreInterface {
/**
* Default session base name.
*/
const BASE_NAME = 'auth0_';
/**
* Default session cookie expiration.
*/
const COOKIE_EXPIRES = 604800;
/**
* Session base name, configurable on instantiation.
*
* @var string
*/
protected $session_base_name = self::BASE_NAME;
/**
* Session cookie expiration, configurable on instantiation.
*
* @var integer
*/
protected $session_cookie_expires;
/**
* SessionStore constructor.
*
* @param string $base_name Session base name.
* @param integer $cookie_expires Session expiration in seconds; default is 1 week - @deprecated 5.7.0
*/
public function __construct($base_name = self::BASE_NAME, $cookie_expires = self::COOKIE_EXPIRES) {
$this->session_base_name = (string) $base_name;
$this->session_cookie_expires = (int) $cookie_expires;
}
/**
* This basic implementation of BaseAuth0 SDK uses
* PHP Sessions to store volatile data.
*
* @return void
*/
private function initSession() {
if (!session_id()) {
if (!empty($this->session_cookie_expires)) {
session_set_cookie_params($this->session_cookie_expires);
}
session_start();
}
}
/**
* Persists $value on $_SESSION, identified by $key.
*
* @param string $key Session key to set.
* @param mixed $value Value to use.
*
* @return void
*/
public function set($key, $value) {
$this
->initSession();
$key_name = $this
->getSessionKeyName($key);
$_SESSION[$key_name] = $value;
}
/**
* Gets persisted values identified by $key.
* If the value is not set, returns $default.
*
* @param string $key Session key to set.
* @param mixed $default Default to return if nothing was found.
*
* @return mixed
*/
public function get($key, $default = null) {
$this
->initSession();
$key_name = $this
->getSessionKeyName($key);
if (isset($_SESSION[$key_name])) {
return $_SESSION[$key_name];
}
else {
return $default;
}
}
/**
* Removes a persisted value identified by $key.
*
* @param string $key Session key to delete.
*
* @return void
*/
public function delete($key) {
$this
->initSession();
$key_name = $this
->getSessionKeyName($key);
unset($_SESSION[$key_name]);
}
/**
* Constructs a session key name.
*
* @param string $key Session key name to prefix and return.
*
* @return string
*/
public function getSessionKeyName($key) {
$key_name = $key;
if (!empty($this->session_base_name)) {
$key_name = $this->session_base_name . '_' . $key_name;
}
return $key_name;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SessionStore:: |
protected | property | Session base name, configurable on instantiation. | |
SessionStore:: |
protected | property | Session cookie expiration, configurable on instantiation. | |
SessionStore:: |
constant | Default session base name. | ||
SessionStore:: |
constant | Default session cookie expiration. | ||
SessionStore:: |
public | function |
Removes a persisted value identified by $key. Overrides StoreInterface:: |
|
SessionStore:: |
public | function |
Gets persisted values identified by $key.
If the value is not set, returns $default. Overrides StoreInterface:: |
|
SessionStore:: |
public | function | Constructs a session key name. | |
SessionStore:: |
private | function | This basic implementation of BaseAuth0 SDK uses PHP Sessions to store volatile data. | |
SessionStore:: |
public | function |
Persists $value on $_SESSION, identified by $key. Overrides StoreInterface:: |
|
SessionStore:: |
public | function | SessionStore constructor. |