You are here

protected function JanrainCaptureApi::cache in Janrain Registration 8

Returns existing, newly added or updated access token from the database.

Parameters

\Drupal\janrain_capture\Authentication\AccessToken|null $access_token: The access token. Can be omitted to read an existing one.

Return value

\Drupal\janrain_capture\Authentication\AccessToken|null The access token.

2 calls to JanrainCaptureApi::cache()
JanrainCaptureApi::authenticate in src/JanrainCaptureApi.php
Returns requested access token and set it to the current session.
JanrainCaptureApi::getAccessToken in src/JanrainCaptureApi.php
Returns an access token from the database and prolongs it automatically.

File

src/JanrainCaptureApi.php, line 246

Class

JanrainCaptureApi
The integration between Janrain and Drupal.

Namespace

Drupal\janrain_capture

Code

protected function cache(AccessToken $access_token = NULL) : ?AccessToken {
  $user_id = $this->currentUser
    ->id();
  if ($user_id < 1) {
    throw new \LogicException('Cannot read/store an access token for an unauthenticated user.');
  }
  $cache_key = "{$user_id}:access_token";
  if ($access_token === NULL) {
    return $this->dbStorage
      ->get($cache_key);
  }
  $this->dbStorage
    ->set($cache_key, $access_token);
  return $access_token;
}