private function _parseAccessTokenResponse(HttpClient $http, $oldRefreshToken = null)
{
$headers = $http->getHeaders();
$type = 'text';
if (isset($headers['Content-Type']) && strpos($headers['Content-Type'], 'application/json') !== false) {
$type = 'json';
}
switch ($type) {
case 'json':
$response = json_decode($http->getResponse(), true);
break;
case 'text':
default:
$response = HttpClient::parseStringToArray($http->getResponse(), '&', '=');
break;
}
if (isset($response['error'])) {
throw new Exception('got error while requesting access token: ' . $response['error']);
}
if (!isset($response['access_token'])) {
throw new Exception('no access_token found');
}
$token = new Token($response['access_token'], isset($response['refresh_token']) ? $response['refresh_token'] : $oldRefreshToken, isset($response['expires_in']) ? $response['expires_in'] : null);
unset($response['access_token']);
unset($response['refresh_token']);
unset($response['expires_in']);
// add additional parameters which may be returned depending on service and scope
foreach ($response as $key => $value) {
$token->{'set' . $key}($value);
}
$this->_dataStore->storeAccessToken($token);
return $token;
}