/**
  * Bind the storage implementations to the IoC container
  * @return void
  */
 public function registerStorageBindings()
 {
     $redis = new RedisCapsule($this->app['config']->get('database.oauth2-redis'));
     $redis->setAsGlobal();
     $this->app->bindShared('Fahmiardi\\OAuth2\\Server\\Storage\\Redis\\RedisAccessToken', function () {
         return new RedisAccessToken();
     });
     $this->app->bindShared('Fahmiardi\\OAuth2\\Server\\Storage\\Redis\\RedisClient', function () {
         return new RedisClient();
     });
     $this->app->bindShared('Fahmiardi\\OAuth2\\Server\\Storage\\Redis\\RedisScope', function () {
         return new RedisScope();
     });
     $this->app->bindShared('Fahmiardi\\OAuth2\\Server\\Storage\\Redis\\RedisSession', function () {
         return new RedisSession();
     });
 }
 /**
  * {@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());
 }
 /**
  * Dynamically pass redis command
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return mixed
  */
 public static function __callStatic($method, $parameters)
 {
     return static::$instance->command($method, $parameters);
 }
 /**
  * {@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));
 }