/** * {@inheritdoc} */ function refreshToken() { // have an access token? if ($this->api->access_token) { // have to refresh? if ($this->api->refresh_token && $this->api->access_token_expires_at) { // expired? if ($this->api->access_token_expires_at <= time()) { $response = $this->api->refreshToken(array("refresh_token" => $this->api->refresh_token)); if (!isset($response->access_token) || !$response->access_token) { // set the user as disconnected at this point and throw an exception $this->setUserUnconnected(); throw new Exception("The Authorization Service has return an invalid response while requesting a new access token. " . (string) $response->error); } // set new access_token $this->api->access_token = $response->access_token; if (isset($response->refresh_token)) { $this->api->refresh_token = $response->refresh_token; } if (isset($response->expires_in)) { $this->api->access_token_expires_in = $response->expires_in; // even given by some idp, we should calculate this $this->api->access_token_expires_at = time() + $response->expires_in; } } } // re store tokens $this->token("access_token", $this->api->access_token); $this->token("refresh_token", $this->api->refresh_token); $this->token("expires_in", $this->api->access_token_expires_in); $this->token("expires_at", $this->api->access_token_expires_at); } }