From ea5c76f012d191f19269849c68864da5a870f72b Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 11 Jun 2020 12:13:39 +0300 Subject: [PATCH] oauth changes --- .../Espo/Core/ExternalAccount/ClientManager.php | 15 ++++++++++++--- .../ExternalAccount/Clients/OAuth2Abstract.php | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/application/Espo/Core/ExternalAccount/ClientManager.php b/application/Espo/Core/ExternalAccount/ClientManager.php index d6f373b46f..328b0eccd9 100644 --- a/application/Espo/Core/ExternalAccount/ClientManager.php +++ b/application/Espo/Core/ExternalAccount/ClientManager.php @@ -127,7 +127,8 @@ class ClientManager $client->setup( $userId, $integrationEntity, - $externalAccountEntity + $externalAccountEntity, + $this ); $this->addToClientMap($client, $integrationEntity, $externalAccountEntity, $userId); @@ -162,7 +163,7 @@ class ClientManager $oauth2Client = new \Espo\Core\ExternalAccount\OAuth2\Client(); - $client = new $className($oauth2Client, [ + $params = [ 'endpoint' => $this->getMetadata()->get("integrations.{$integration}.params.endpoint"), 'tokenEndpoint' => $this->getMetadata()->get("integrations.{$integration}.params.tokenEndpoint"), 'clientId' => $integrationEntity->get('clientId'), @@ -172,7 +173,15 @@ class ClientManager 'refreshToken' => $externalAccountEntity->get('refreshToken'), 'tokenType' => $externalAccountEntity->get('tokenType'), 'expiresAt' => $externalAccountEntity->get('expiresAt'), - ], $this); + ]; + + foreach (get_object_vars($integrationEntity->getValueMap()) as $k => $v) { + if (array_key_exists($k, $params)) continue; + if ($integrationEntity->hasAttribute($k)) continue; + $params[$k] = $v; + } + + $client = new $className($oauth2Client, $params, $this); $this->addToClientMap($client, $integrationEntity, $externalAccountEntity, $userId); diff --git a/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php b/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php index b20cf98fb1..8e7fbff75f 100644 --- a/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php +++ b/application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php @@ -181,7 +181,7 @@ abstract class OAuth2Abstract implements IClient if ($this->getParam('expiresAt')) { try { $dt = new \DateTime($this->getParam('expiresAt')); - $dt->modify('-' . self::ACCESS_TOKEN_EXPIRATION_MARGIN); + $dt->modify('-' . $this::ACCESS_TOKEN_EXPIRATION_MARGIN); } catch (\Exception $e) { return; } @@ -189,11 +189,11 @@ abstract class OAuth2Abstract implements IClient if ($dt->format('U') <= (new \DateTime())->format('U')) { $GLOBALS['log']->debug("Oauth: Refreshing expired token for client {$this->clientId}."); - $until = microtime(true) + self::LOCK_TIMEOUT; + $until = microtime(true) + $this::LOCK_TIMEOUT; if ($this->isLocked()) { while (true) { - usleep(self::LOCK_CHECK_STEP * 1000000); + usleep($this::LOCK_CHECK_STEP * 1000000); if (!$this->isLocked()) { $GLOBALS['log']->debug("Oauth: Waited until unlocked for client {$this->clientId}.");