/** * refresh access token * * @param \OAuth2\Token $token * @return \OAuth2\Token new token object */ public function refreshAccessToken(Token $token) { if (!$token->getRefreshToken()) { throw new Exception('could not refresh access token, no refresh token available'); } $parameters = array('grant_type' => 'refresh_token', 'type' => 'web_server', 'client_id' => $this->_client->getClientKey(), 'client_secret' => $this->_client->getClientSecret(), 'refresh_token' => $token->getRefreshToken()); $http = new HttpClient($this->_configuration->getAccessTokenEndpoint(), 'POST', http_build_query($parameters)); $http->execute(); return $this->_parseAccessTokenResponse($http, $token->getRefreshToken()); }
/** * revoke access token * * @return bool */ public function revokeAccessToken() { if (!$this->_dataStore->retrieveAccessToken()->getAccessToken()) { throw new Exception('could not revoke access token, no access token found, did you forgot call autorize()!!'); } if (!$this->_configuration->getRevokeEndpoint()) { throw new Exception('no revoke end point found.'); } $parameters = array('type' => 'web_server', 'client_id' => $this->_client->getClientKey(), 'access_token' => $this->_dataStore->retrieveAccessToken()->getAccessToken()); $http = new HttpClient($this->_configuration->getRevokeEndpoint(), 'POST', http_build_query($parameters)); $http->execute(); $headers = $http->getHeaders(); if ($http->getHeader('http_code') == '200') { // remove session details access_token, refresh_token, ... $this->_dataStore->removeAccessToken(); return true; } else { return false; } }