diff --git a/php/elFinderVolumeBox.class.php b/php/elFinderVolumeBox.class.php index fc6daa2f5..a7ab8b081 100644 --- a/php/elFinderVolumeBox.class.php +++ b/php/elFinderVolumeBox.class.php @@ -228,23 +228,24 @@ class elFinderVolumeBox extends elFinderVolumeDriver /** * Get token and auto refresh. * - * @param object $box Box API client - * * @return true|string error message */ - protected function _bd_refreshToken($token) + protected function _bd_refreshToken() { - if ($token->expires < time()) { + if ($this->token->expires < time()) { + if (!$token = $this->session->get('BoxTokens')) { + $token = $this->token; + } if (empty($token->data->refresh_token)) { $this->session->remove('BoxTokens'); throw new \Exception(elFinder::ERROR_REAUTH_REQUIRE); } - if (null === $this->options['client_id']) { + if (!$this->options['client_id']) { $this->options['client_id'] = ELFINDER_BOX_CLIENTID; } - if (null === $this->options['client_secret']) { + if (!$this->options['client_secret']) { $this->options['client_secret'] = ELFINDER_BOX_CLIENTSECRET; } @@ -271,7 +272,7 @@ class elFinderVolumeBox extends elFinderVolumeDriver $result = curl_exec($curl); - if (false === $result) { + if (!$result) { if (curl_errno($curl)) { throw new \Exception('curl_setopt_array() failed: '.curl_error($curl)); } else { @@ -283,7 +284,7 @@ class elFinderVolumeBox extends elFinderVolumeDriver $decoded = json_decode($result); - if (null === $decoded) { + if (!$decoded) { throw new \Exception('json_decode() failed'); } @@ -621,7 +622,7 @@ class elFinderVolumeBox extends elFinderVolumeDriver if ($this->token) { try { - $this->_bd_refreshToken($this->token); + $this->_bd_refreshToken(); } catch (Exception $e) { $this->setError($e->getMessage()); $this->token = null; @@ -745,15 +746,14 @@ class elFinderVolumeBox extends elFinderVolumeDriver return $this->setError('Required option `accessToken` is undefined.'); } - if (!$this->token) { - try { - $this->token = json_decode($this->options['accessToken']); - $this->_bd_refreshToken($this->token); - } catch (Exception $e) { - $this->setError($e->getMessage()); + try { + $this->token = json_decode($this->options['accessToken']); + $this->_bd_refreshToken(); + } catch (Exception $e) { + $this->token = null; + $this->session->remove('BoxTokens'); - return $this->setError($e->getMessage()); - } + return $this->setError($e->getMessage()); } if (empty($options['netkey'])) { diff --git a/php/elFinderVolumeOneDrive.class.php b/php/elFinderVolumeOneDrive.class.php index d93980b05..0dc8fbec6 100644 --- a/php/elFinderVolumeOneDrive.class.php +++ b/php/elFinderVolumeOneDrive.class.php @@ -192,23 +192,24 @@ class elFinderVolumeOneDrive extends elFinderVolumeDriver /** * Get token and auto refresh. * - * @param object $client OneDrive API client - * * @return true|Exception */ - protected function _od_refreshToken($token) + protected function _od_refreshToken() { - if ($token->expires < time()) { - if (empty($this->token->data->refresh_token)) { + if ($this->token->expires < time()) { + if (!$token = $this->session->get('OneDriveTokens')) { + $token = $this->token; + } + if (empty($token->data->refresh_token)) { $this->session->remove('OneDriveTokens'); throw new \Exception(elFinder::ERROR_REAUTH_REQUIRE); } - if (null === $this->options['client_id']) { + if (!$this->options['client_id']) { $this->options['client_id'] = ELFINDER_ONEDRIVE_CLIENTID; } - if (null === $this->options['client_secret']) { + if (!$this->options['client_secret']) { $this->options['client_secret'] = ELFINDER_ONEDRIVE_CLIENTSECRET; } @@ -235,7 +236,7 @@ class elFinderVolumeOneDrive extends elFinderVolumeDriver $result = curl_exec($curl); - if (false === $result) { + if (!$result) { if (curl_errno($curl)) { throw new \Exception('curl_setopt_array() failed: '.curl_error($curl)); } else { @@ -246,7 +247,7 @@ class elFinderVolumeOneDrive extends elFinderVolumeDriver $decoded = json_decode($result); - if (null === $decoded) { + if (!$decoded) { throw new \Exception('json_decode() failed'); } @@ -567,7 +568,7 @@ class elFinderVolumeOneDrive extends elFinderVolumeDriver if ($this->token) { try { - $this->_od_refreshToken($this->token); + $this->_od_refreshToken(); } catch (Exception $e) { $this->setError($e->getMessage()); $this->token = null; @@ -705,15 +706,14 @@ class elFinderVolumeOneDrive extends elFinderVolumeDriver return $this->setError('Required option `accessToken` is undefined.'); } - if (!$this->token) { - try { - $this->token = json_decode($this->options['accessToken']); - $this->_od_refreshToken($this->token); - } catch (Exception $e) { - $this->setError($e->getMessage()); + try { + $this->token = json_decode($this->options['accessToken']); + $this->_od_refreshToken(); + } catch (Exception $e) { + $this->token = null; + $this->session->remove('OneDriveTokens'); - return $this->setError($e->getMessage()); - } + return $this->setError($e->getMessage()); } if (empty($options['netkey'])) {