From f77b9cc1bff94670e5790839e9fc9b868a9a778e Mon Sep 17 00:00:00 2001 From: Noah Miller Date: Thu, 21 Sep 2023 23:39:19 -0400 Subject: [PATCH] make cardinal more reliable; add a little more info to getFields make cardinal more reliable; add a little more info to getFields --- .../Civi/Api4/OAuthSessionToken.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ext/oauth-client/Civi/Api4/OAuthSessionToken.php b/ext/oauth-client/Civi/Api4/OAuthSessionToken.php index 6508f76179..2e9a6b274e 100644 --- a/ext/oauth-client/Civi/Api4/OAuthSessionToken.php +++ b/ext/oauth-client/Civi/Api4/OAuthSessionToken.php @@ -25,12 +25,14 @@ class OAuthSessionToken extends Generic\AbstractEntity { $action = new Generic\BasicCreateAction( static::getEntityName(), __FUNCTION__, - function ($item, $createAction) { + function ($item) { $session = \CRM_Core_Session::singleton(); - $all = $session->get('OAuthSessionTokens') ?? []; - $all[] = &$item; - $item['cardinal'] = array_key_last($all); - $session->set('OAuthSessionTokens', $all); + $allTokens = $session->get('OAuthSessionTokens') ?? []; + $cardinal = ($session->get('OAuthSessionTokenCount') ?? 0) + 1; + $item['cardinal'] = $cardinal; + $allTokens[$cardinal] = $item; + $session->set('OAuthSessionTokens', $allTokens); + $session->set('OAuthSessionTokenCount', $cardinal); return $item; }); return $action->setCheckPermissions($checkPermissions); @@ -69,8 +71,15 @@ class OAuthSessionToken extends Generic\AbstractEntity { [ 'name' => 'client_id', 'required' => TRUE, + 'data_type' => 'Integer', + 'fk_entity' => 'OAuthClient', + ], + [ + 'name' => 'cardinal', + 'readonly' => TRUE, + 'data_type' => 'Integer', + 'description' => 'Order in which the token was created within the current session. Unique within the session.', ], - ['name' => 'cardinal'], ['name' => 'grant_type'], ['name' => 'tag'], ['name' => 'scopes'], -- 2.25.1