Skip to content

Removed object-wide token refresh flag #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class ApiClient implements ApiInterface
private $secret;
private $token;

private $refreshToken = 0;

/**
* @var null|TokenStorageInterface
*/
Expand Down Expand Up @@ -83,7 +81,6 @@ private function getToken()
return false;
}

$this->refreshToken = 0;
$this->token = $requestResult->data->access_token;

$hashName = md5($this->userId . '::' . $this->secret);
Expand All @@ -100,10 +97,11 @@ private function getToken()
* @param string $method
* @param array $data
* @param bool $useToken
* @param bool $tokenRefreshed
*
* @return stdClass
*/
protected function sendRequest($path, $method = 'GET', $data = array(), $useToken = true)
protected function sendRequest($path, $method = 'GET', $data = array(), $useToken = true, $tokenRefreshed = false)
{
$url = $this->apiUrl . '/' . $path;
$method = strtoupper($method);
Expand Down Expand Up @@ -148,10 +146,9 @@ protected function sendRequest($path, $method = 'GET', $data = array(), $useToke

curl_close($curl);

if ($headerCode === 401 && $this->refreshToken === 0) {
++$this->refreshToken;
if ($headerCode === 401 && !$tokenRefreshed) {
$this->getToken();
$retval = $this->sendRequest($path, $method, $data);
$retval = $this->sendRequest($path, $method, $data, true, true);
} else {
$retval = new stdClass();
$retval->data = json_decode($responseBody);
Expand Down