diff --git a/src/OAuth/OAuth2/Service/AbstractService.php b/src/OAuth/OAuth2/Service/AbstractService.php index e5c58783..fac360ec 100644 --- a/src/OAuth/OAuth2/Service/AbstractService.php +++ b/src/OAuth/OAuth2/Service/AbstractService.php @@ -211,6 +211,9 @@ public function refreshAccessToken(TokenInterface $token) $parameters, $this->getExtraOAuthHeaders() ); + + $responseBody = $this->carryRefreshToken($responseBody, $refreshToken); + $token = $this->parseAccessTokenResponse($responseBody); $this->storage->storeAccessToken($this->service(), $token); @@ -241,6 +244,26 @@ public function needsStateParameterInAuthUrl() return $this->stateParameterInAuthUrl; } + /** + * Carry the refresh_token for next time getting refreshed + * + * @param $responseBody + * + * @param $refreshToken + * + * @return string + */ + protected function carryRefreshToken($responseBody, $refreshToken) + { + $responseJson = json_decode($responseBody, true); + if (empty($responseJson['refresh_token'])) { + $responseJson['refresh_token'] = $refreshToken; + return json_encode($responseJson); + } else { + return $responseBody; + } + } + /** * Validates the authorization state against a given one. *