diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d07d2c..bd43fc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.0.1 + +* fixed unsetting access token stored inside session on error + ## 2.0.0 * added funnel endpoints diff --git a/src/Client.php b/src/Client.php index fb99721..83e7281 100644 --- a/src/Client.php +++ b/src/Client.php @@ -56,6 +56,8 @@ class Client { 'utm_source' ); + const SESSION_TOKEN_KEY = 'pirsch_access_token'; + private $clientID; private $clientSecret; private $client; @@ -440,6 +442,8 @@ private function performGet($url, Filter $filter, $retry = true) { private function refreshToken() { try { + unset($_SESSION[self::SESSION_TOKEN_KEY]); + if (empty($this->clientID)) { throw new \Exception('Single access tokens cannot be refreshed'); } @@ -460,7 +464,7 @@ private function refreshToken() { } $resp = json_decode($response->getBody()); - $_SESSION['pirsch_access_token'] = $resp->access_token; + $_SESSION[self::SESSION_TOKEN_KEY] = $resp->access_token; } catch(\GuzzleHttp\Exception\RequestException $e) { if (!is_null($e->getResponse()) && $e->getResponse()->getStatusCode() != 200) { throw new \Exception('Error refreshing token '.!is_null($e->getResponse()) && $e->getResponse()->getStatusCode().': '.$e->getResponse()->getBody()); @@ -478,8 +482,8 @@ private function getRequestHeader() { private function getAccessToken() { if (empty($this->clientID)) { return $this->clientSecret; - } else if (isset($_SESSION['pirsch_access_token'])) { - return $_SESSION['pirsch_access_token']; + } else if (isset($_SESSION[self::SESSION_TOKEN_KEY])) { + return $_SESSION[self::SESSION_TOKEN_KEY]; } return '';