oauth changes

This commit is contained in:
Yuri Kuznetsov
2020-06-11 12:13:39 +03:00
parent acb9b50d14
commit ea5c76f012
2 changed files with 15 additions and 6 deletions

View File

@@ -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);

View File

@@ -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}.");