Skip to content

Commit

Permalink
implement-basicbatchaction-getselect
Browse files Browse the repository at this point in the history
  • Loading branch information
ufundo committed Aug 23, 2021
1 parent e35e612 commit afc100a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ext/oauth-client/Civi/Api4/Action/OAuthSysToken/Refresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ class Refresh extends BasicBatchAction {

private $syncFields = ['access_token', 'refresh_token', 'expires', 'token_type'];
private $writeFields = ['access_token', 'refresh_token', 'expires', 'token_type', 'raw'];
private $selectFields = ['id', 'client_id', 'access_token', 'refresh_token', 'expires', 'token_type', 'raw'];
private $providers = [];

public function __construct($entityName, $actionName) {
parent::__construct($entityName, $actionName, '*');
parent::__construct($entityName, $actionName);
}

protected function getSelect() {
return $this->selectFields;
}

protected function doTask($row) {

if ($this->threshold >= 0 && \CRM_Utils_Time::getTimeRaw() < $row['expires'] - $this->threshold) {
return $this->filterReturn($row);
}
Expand Down Expand Up @@ -73,14 +79,17 @@ protected function doTask($row) {
}

protected function getProvider($clientId) {

if (!isset($this->providers[$clientId])) {
$client = \Civi\Api4\OAuthClient::get(0)->addWhere('id', '=', $clientId)->execute()->single();

$this->providers[$clientId] = \Civi::service('oauth2.league')->createProvider($client);
}
return $this->providers[$clientId];
}

protected function filterReturn($tokenRecord) {

return $this->checkPermissions ? \CRM_OAuth_BAO_OAuthSysToken::redact($tokenRecord) : $tokenRecord;
}

Expand Down

0 comments on commit afc100a

Please sign in to comment.