From 9a649260e2ba5ccdaed21d8e4d1feea6e08c199a Mon Sep 17 00:00:00 2001 From: constant-bouquet Date: Tue, 23 Jul 2024 19:10:44 +0200 Subject: [PATCH] Fix Outh2 refresh token --- src/Bynder/Api/Impl/OAuth2/Configuration.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Bynder/Api/Impl/OAuth2/Configuration.php b/src/Bynder/Api/Impl/OAuth2/Configuration.php index f56a165..4caae39 100644 --- a/src/Bynder/Api/Impl/OAuth2/Configuration.php +++ b/src/Bynder/Api/Impl/OAuth2/Configuration.php @@ -10,6 +10,7 @@ namespace Bynder\Api\Impl\OAuth2; use Bynder\Api\Impl\Oauth2\BynderOauthProvider; +use League\OAuth2\Client\Token\AccessToken; /** * Class to hold Oauth2 tokens necessary for every API request. @@ -122,11 +123,18 @@ public function refreshToken(BynderOauthProvider $oauthProvider) return; } - $this->setToken( - $oauthProvider->getAccessToken('refresh_token', [ - 'refresh_token' => $this->getToken()->getRefreshToken() - ]) - ); + $oldRefreshToken = $this->getToken()->getRefreshToken(); + + $token = $oauthProvider->getAccessToken('refresh_token', [ + 'refresh_token' => $oldRefreshToken + ]); + + $options = $token->jsonSerialize(); + if (empty($options['refresh_token'])) { + $options['refresh_token'] = $oldRefreshToken; + } + + $this->setToken(new AccessToken($options)); } public function getRequestOptions()