/**
  * {@inheritdoc}
  */
 public function getBySession(SessionEntity $session)
 {
     $key = RedisUtil::prefix($session->getId(), 'oauth_sessions');
     if (isset($this->cache[$key])) {
         $result = $this->cache[$key];
     } else {
         if (!($value = RedisCapsule::get($key))) {
             return;
         }
         $result = $this->cache[$key] = RedisUtil::unserialize($value);
     }
     return $this->get($result['client_id']);
 }
 /**
  * {@inheritdoc}
  */
 public function get($scope, $grantType = null, $clientId = null)
 {
     $key = RedisUtil::prefix($scope, 'oauth_scopes');
     if (isset($this->cache[$key])) {
         $result = $this->cache[$key];
     } else {
         if (!($value = RedisCapsule::get($key))) {
             return;
         }
         $result = $this->cache[$key] = RedisUtil::unserialize($value);
     }
     return (new ScopeEntity($this->server))->hydrate(['id' => $result['id'], 'description' => $result['description']]);
 }
 /**
  * {@inheritdoc}
  */
 public function delete(RefreshTokenEntity $token)
 {
     // Deletes the access token entry.
     $key = RedisUtil::prefix($token->getId(), 'oauth_refresh_tokens');
     if (isset($this->cache[$key])) {
         unset($this->cache[$key]);
     }
     RedisCapsule::del($key);
     // Deletes the access token entry from the access tokens set.
     $key = RedisUtil::prefix(null, 'oauth_refresh_tokens');
     if (isset($this->cache[$key]) && ($cacheKey = array_search($token->getId(), $this->cache[$key])) !== false) {
         unset($this->cache[$key][$cacheKey]);
     }
     RedisCapsule::srem($key, $token->getId());
 }
 /**
  * {@inheritdoc}
  */
 public function delete(AuthCodeEntity $token)
 {
     // // Deletes the authorization code entry.
     $key = RedisUtil::prefix($token->getId(), 'oauth_auth_codes');
     if (isset($this->cache[$key])) {
         unset($this->cache[$key]);
     }
     RedisCapsule::del($key);
     // // Deletes the authorization code entry from the authorization codes set.
     $key = RedisUtil::prefix(null, 'oauth_auth_codes');
     if (isset($this->cache[$key]) && ($cacheKey = array_search($token->getId(), $this->cache[$key])) !== false) {
         unset($this->cache[$key][$cacheKey]);
     }
     RedisCapsule::srem($key, $token->getId());
     // // Deletes the authorization codes associated scopes.
     $key = RedisUtil::prefix($token->getId(), 'oauth_auth_code_scopes');
     if (isset($this->cache[$key])) {
         unset($this->cache[$key]);
     }
     RedisCapsule::del($key);
 }
 /**
  * {@inheritdoc}
  */
 public function associateScope(SessionEntity $session, ScopeEntity $scope)
 {
     $key = RedisUtil::prefix($session->getId(), 'oauth_session_scopes');
     if (!isset($this->cache[$key])) {
         $this->cache[$key] = [];
     }
     $value = ['id' => $scope->getId()];
     array_push($this->cache[$key], $value);
     RedisCapsule::sadd($key, RedisUtil::prepare($value));
 }