diff --git a/application/Espo/Core/ExternalAccount/ClientManager.php b/application/Espo/Core/ExternalAccount/ClientManager.php index f2266d857b..3245ef418a 100644 --- a/application/Espo/Core/ExternalAccount/ClientManager.php +++ b/application/Espo/Core/ExternalAccount/ClientManager.php @@ -71,11 +71,18 @@ class ClientManager $externalAccountEntity->set('tokenType', $data['tokenType']); $externalAccountEntity->set('expiresAt', $data['expiresAt'] ?? null); + if ($data['refreshToken'] ?? null) { + $externalAccountEntity->set('refreshToken', $data['refreshToken']); + } + $copy = $this->getEntityManager()->getEntity('ExternalAccount', $externalAccountEntity->id); if ($copy) { $copy->set('accessToken', $data['accessToken']); $copy->set('tokenType', $data['tokenType']); $copy->set('expiresAt', $data['expiresAt'] ?? null); + if ($data['refreshToken'] ?? null) { + $copy->set('refreshToken', $data['refreshToken'] ?? null); + } $this->getEntityManager()->saveEntity($copy, ['isTokenRenewal' => true]); } } diff --git a/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php b/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php index 4f73abdf74..2d1ea446c1 100644 --- a/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php +++ b/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php @@ -115,6 +115,10 @@ abstract class OAuth2Abstract implements IClient $data['expiresAt'] = null; + if (isset($result['refresh_token']) && $result['refresh_token'] !== $this->refreshToken) { + $data['refreshToken'] = $result['refresh_token']; + } + if (isset($result['expires_in']) && is_numeric($result['expires_in'])) { $data['expiresAt'] = (new \DateTime()) ->modify('+' . $result['expires_in'] . ' seconds')