From 3e886bec14cc345e64688aae3dafd0f2ee5be529 Mon Sep 17 00:00:00 2001 From: sanchapereira <2354712+sanchapereira@users.noreply.github.com> Date: Thu, 21 May 2026 10:28:41 +0000 Subject: [PATCH 1/2] Upgrade after onfido-openapi-spec change 6a36202 --- .release.json | 8 +- README.md | 21 +++ composer.json | 2 +- composer.lock | 2 +- lib/Api/DefaultApi.php | 316 +++++++++++++++++++++++++++++++++++++++++ lib/Configuration.php | 109 +++++++++++++- 6 files changed, 450 insertions(+), 8 deletions(-) diff --git a/.release.json b/.release.json index 057d2a1..09a5418 100644 --- a/.release.json +++ b/.release.json @@ -1,9 +1,9 @@ { "source": { "repo_url": "https://github.com/onfido/onfido-openapi-spec", - "short_sha": "6a19890", - "long_sha": "6a198909828b3935c65b669e44cf2927e84957c0", - "version": "v6.0.1" + "short_sha": "6a36202", + "long_sha": "6a362029f0a58437e8be7185303ef14d3f342feb", + "version": "v6.1.0" }, - "release": "v10.1.0" + "release": "v10.2.0" } diff --git a/README.md b/README.md index 4ecf75c..144af27 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,27 @@ $onfidoApi = new Onfido\Api\DefaultApi( ``` +You can also authenticate using OAuth2 client credentials instead of an API token: + +```php +setOAuthCredentials($_ENV['ONFIDO_OAUTH_CLIENT_ID'], $_ENV['ONFIDO_OAUTH_CLIENT_SECRET']); +$configuration->setRegion(Onfido\Region::EU); // Supports `Region::EU`, `Region::US`, and `Region::CA` + +$onfidoApi = new Onfido\Api\DefaultApi( + new \GuzzleHttp\Client([ + 'timeout' => 30, + 'connect_timeout' => 30, + 'read_timeout' => 30 + ]), $configuration); + +``` + +The client will automatically exchange credentials for an access token and refresh it when it expires. + ### Making a call to the API ```php diff --git a/composer.json b/composer.json index f30a29f..9f0477a 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "onfido/onfido-php", - "version": "10.1.0", + "version": "10.2.0", "description": "The Onfido Public API (v3.6)", "keywords": [ "openapitools", diff --git a/composer.lock b/composer.lock index 44fbfb8..2b600af 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "db04786b705dc21f3f52f9052be9025c", + "content-hash": "efa9c4e7a1c904ac7ad6ea50671dde56", "packages": [ { "name": "guzzlehttp/guzzle", diff --git a/lib/Api/DefaultApi.php b/lib/Api/DefaultApi.php index 1d7941d..45eaca0 100644 --- a/lib/Api/DefaultApi.php +++ b/lib/Api/DefaultApi.php @@ -563,6 +563,10 @@ public function cancelReportRequest($report_id, string $contentType = self::cont } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -833,6 +837,10 @@ public function completeTaskRequest($workflow_run_id, $task_id, $complete_task_b } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -1119,6 +1127,10 @@ public function createApplicantRequest($applicant_builder, string $contentType = } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -1405,6 +1417,10 @@ public function createCheckRequest($check_builder, string $contentType = self::c } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -1692,6 +1708,10 @@ public function createTimelineFileRequest($workflow_run_id, string $contentType } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -1978,6 +1998,10 @@ public function createWatchlistMonitorRequest($watchlist_monitor_builder, string } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -2264,6 +2288,10 @@ public function createWebhookRequest($webhook_builder, string $contentType = sel } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -2550,6 +2578,10 @@ public function createWorkflowRunRequest($workflow_run_builder, string $contentT } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -2781,6 +2813,10 @@ public function deleteApplicantRequest($applicant_id, string $contentType = self } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -3032,6 +3068,10 @@ public function deletePasskeyRequest($username, $passkey_id, string $contentType } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -3263,6 +3303,10 @@ public function deletePasskeysRequest($username, string $contentType = self::con } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -3494,6 +3538,10 @@ public function deleteWatchlistMonitorRequest($monitor_id, string $contentType = } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -3725,6 +3773,10 @@ public function deleteWebhookRequest($webhook_id, string $contentType = self::co } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -4034,6 +4086,10 @@ public function downloadAesDocumentRequest($workflow_run_id, $id, string $conten } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -4321,6 +4377,10 @@ public function downloadCheckRequest($check_id, string $contentType = self::cont } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -4608,6 +4668,10 @@ public function downloadDocumentRequest($document_id, string $contentType = self } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -4895,6 +4959,10 @@ public function downloadDocumentVideoRequest($document_id, string $contentType = } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -5182,6 +5250,10 @@ public function downloadEvidenceFolderRequest($workflow_run_id, string $contentT } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -5469,6 +5541,10 @@ public function downloadIdPhotoRequest($id_photo_id, string $contentType = self: } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -5756,6 +5832,10 @@ public function downloadLivePhotoRequest($live_photo_id, string $contentType = s } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -6043,6 +6123,10 @@ public function downloadLiveVideoRequest($live_video_id, string $contentType = s } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -6330,6 +6414,10 @@ public function downloadLiveVideoFrameRequest($live_video_id, string $contentTyp } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -6617,6 +6705,10 @@ public function downloadMotionCaptureRequest($motion_capture_id, string $content } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -6904,6 +6996,10 @@ public function downloadMotionCaptureFrameRequest($motion_capture_id, string $co } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -7191,6 +7287,10 @@ public function downloadNfcFaceRequest($document_id, string $contentType = self: } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -7500,6 +7600,10 @@ public function downloadQesDocumentRequest($workflow_run_id, $file_id, string $c } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -7809,6 +7913,10 @@ public function downloadSesDocumentRequest($workflow_run_id, $id, string $conten } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -8096,6 +8204,10 @@ public function downloadSignedEvidenceFileRequest($workflow_run_id, string $cont } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -8383,6 +8495,10 @@ public function downloadSigningDocumentRequest($signing_document_id, string $con } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -8669,6 +8785,10 @@ public function extractRequest($extract_request, string $contentType = self::con } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -8957,6 +9077,10 @@ public function findAddressesRequest($postcode, string $contentType = self::cont } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -9244,6 +9368,10 @@ public function findApplicantRequest($applicant_id, string $contentType = self:: } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -9531,6 +9659,10 @@ public function findApplicantConsentsRequest($applicant_id, string $contentType } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -9818,6 +9950,10 @@ public function findCheckRequest($check_id, string $contentType = self::contentT } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -10105,6 +10241,10 @@ public function findDocumentRequest($document_id, string $contentType = self::co } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -10392,6 +10532,10 @@ public function findIdPhotoRequest($id_photo_id, string $contentType = self::con } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -10679,6 +10823,10 @@ public function findLivePhotoRequest($live_photo_id, string $contentType = self: } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -10966,6 +11114,10 @@ public function findLiveVideoRequest($live_video_id, string $contentType = self: } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -11253,6 +11405,10 @@ public function findMotionCaptureRequest($motion_capture_id, string $contentType } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -11560,6 +11716,10 @@ public function findPasskeyRequest($username, $passkey_id, string $contentType = } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -11847,6 +12007,10 @@ public function findReportRequest($report_id, string $contentType = self::conten } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -12134,6 +12298,10 @@ public function findSigningDocumentRequest($signing_document_id, string $content } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -12441,6 +12609,10 @@ public function findTaskRequest($workflow_run_id, $task_id, string $contentType } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -12748,6 +12920,10 @@ public function findTimelineFileRequest($workflow_run_id, $timeline_file_id, str } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -13035,6 +13211,10 @@ public function findWatchlistMonitorRequest($monitor_id, string $contentType = s } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -13322,6 +13502,10 @@ public function findWebhookRequest($webhook_id, string $contentType = self::cont } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -13609,6 +13793,10 @@ public function findWorkflowRunRequest($workflow_run_id, string $contentType = s } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -13840,6 +14028,10 @@ public function forceReportCreationFromWatchlistMonitorRequest($monitor_id, stri } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -14126,6 +14318,10 @@ public function generateSdkTokenRequest($sdk_token_builder, string $contentType } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -14438,6 +14634,10 @@ public function listApplicantsRequest($page = 1, $per_page = 20, $include_delete } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -14726,6 +14926,10 @@ public function listChecksRequest($applicant_id, string $contentType = self::con } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -15014,6 +15218,10 @@ public function listDocumentsRequest($applicant_id, string $contentType = self:: } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -15302,6 +15510,10 @@ public function listIdPhotosRequest($applicant_id, string $contentType = self::c } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -15590,6 +15802,10 @@ public function listLivePhotosRequest($applicant_id, string $contentType = self: } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -15878,6 +16094,10 @@ public function listLiveVideosRequest($applicant_id, string $contentType = self: } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -16166,6 +16386,10 @@ public function listMotionCapturesRequest($applicant_id, string $contentType = s } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -16453,6 +16677,10 @@ public function listPasskeysRequest($username, string $contentType = self::conte } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -16740,6 +16968,10 @@ public function listRepeatAttemptsRequest($report_id, string $contentType = self } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -17028,6 +17260,10 @@ public function listReportsRequest($check_id, string $contentType = self::conten } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -17316,6 +17552,10 @@ public function listSigningDocumentsRequest($applicant_id, string $contentType = } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -17603,6 +17843,10 @@ public function listTasksRequest($workflow_run_id, string $contentType = self::c } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -17876,6 +18120,10 @@ public function listWatchlistMonitorMatchesRequest($monitor_id, string $contentT } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -18179,6 +18427,10 @@ public function listWatchlistMonitorsRequest($applicant_id, $include_deleted = f } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -18446,6 +18698,10 @@ public function listWebhooksRequest(string $contentType = self::contentTypes['li } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -18818,6 +19074,10 @@ public function listWorkflowRunsRequest($page = 1, $status = null, $created_at_g } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -19085,6 +19345,10 @@ public function pingRequest(string $contentType = self::contentTypes['ping'][0]) } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -19371,6 +19635,10 @@ public function postResultsFeedbackRequest($results_feedback, string $contentTyp } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -19601,6 +19869,10 @@ public function resendWebhooksRequest($webhook_resend, string $contentType = sel } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -19832,6 +20104,10 @@ public function restoreApplicantRequest($applicant_id, string $contentType = sel } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -20063,6 +20339,10 @@ public function resumeCheckRequest($check_id, string $contentType = self::conten } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -20294,6 +20574,10 @@ public function resumeReportRequest($report_id, string $contentType = self::cont } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -20600,6 +20884,10 @@ public function updateApplicantRequest($applicant_id, $applicant_updater, string } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -20926,6 +21214,10 @@ public function updatePasskeyRequest($username, $passkey_id, $passkey_updater, s } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -21232,6 +21524,10 @@ public function updateWatchlistMonitorMatchRequest($monitor_id, $watchlist_monit } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -21538,6 +21834,10 @@ public function updateWebhookRequest($webhook_id, $webhook_updater, string $cont } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -21888,6 +22188,10 @@ public function uploadDocumentRequest($type, $applicant_id, $file, $file_type = } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -22178,6 +22482,10 @@ public function uploadIdPhotoRequest($applicant_id = null, $file = null, string } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -22475,6 +22783,10 @@ public function uploadLivePhotoRequest($applicant_id = null, $file = null, $adva } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { @@ -22777,6 +23089,10 @@ public function uploadSigningDocumentRequest($applicant_id, $file, string $conte } } + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('Authorization'); if ($apiKey !== null) { diff --git a/lib/Configuration.php b/lib/Configuration.php index 1419d83..905516c 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -67,6 +67,34 @@ class Configuration */ protected $accessToken = ''; + /** + * OAuth2 client ID for client credentials flow + * + * @var string|null + */ + protected $oauthClientId = null; + + /** + * OAuth2 client secret for client credentials flow + * + * @var string|null + */ + protected $oauthClientSecret = null; + + /** + * Cached OAuth2 access token + * + * @var string|null + */ + private $oauthAccessToken = null; + + /** + * OAuth2 token expiry timestamp + * + * @var float + */ + private $oauthTokenExpiresAt = 0; + /** * Boolean format for query string * @@ -87,7 +115,7 @@ class Configuration * * @var string */ - protected $userAgent = 'onfido-php/10.1.0'; + protected $userAgent = 'onfido-php/10.2.0'; /** * Debug switch (default set to false) @@ -128,6 +156,9 @@ public function __construct() */ public function setApiToken($apiToken) { + if ($this->oauthClientId !== null) { + throw new \InvalidArgumentException('Cannot set API token when OAuth credentials are already configured'); + } return $this->setApiKey('Authorization', "Token token=$apiToken"); } @@ -145,6 +176,36 @@ public function setRegion($region) return $this; } + /** + * Sets OAuth2 client credentials for authentication. + * The client will automatically exchange credentials for an access token + * and refresh it when expired. This is mutually exclusive with setApiToken. + * + * @param string $clientId OAuth2 client ID + * @param string $clientSecret OAuth2 client secret + * + * @return $this + */ + public function setOAuthCredentials($clientId, $clientSecret) + { + if (empty($clientId)) { + throw new \InvalidArgumentException('OAuth client ID must not be empty'); + } + if (empty($clientSecret)) { + throw new \InvalidArgumentException('OAuth client secret must not be empty'); + } + if ($this->getApiKey('Authorization') !== null) { + throw new \InvalidArgumentException('Cannot set OAuth credentials when API token is already configured'); + } + + $this->oauthClientId = $clientId; + $this->oauthClientSecret = $clientSecret; + $this->oauthAccessToken = null; + $this->oauthTokenExpiresAt = 0; + + return $this; + } + /** @@ -404,7 +465,7 @@ public static function toDebugReport() $report .= ' OS: ' . php_uname() . PHP_EOL; $report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL; $report .= ' The version of the OpenAPI document: v3.6' . PHP_EOL; - $report .= ' SDK Package Version: 10.1.0' . PHP_EOL; + $report .= ' SDK Package Version: 10.2.0' . PHP_EOL; $report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL; return $report; @@ -419,6 +480,11 @@ public static function toDebugReport() */ public function getApiKeyWithPrefix($apiKeyIdentifier) { + // If OAuth credentials are configured, return Bearer token + if ($apiKeyIdentifier === 'Authorization' && $this->oauthClientId !== null) { + return 'Bearer ' . $this->getOAuthAccessToken(); + } + $prefix = $this->getApiKeyPrefix($apiKeyIdentifier); $apiKey = $this->getApiKey($apiKeyIdentifier); @@ -435,6 +501,45 @@ public function getApiKeyWithPrefix($apiKeyIdentifier) return $keyWithPrefix; } + + /** + * Fetches or returns a cached OAuth2 access token. + * + * @return string The OAuth2 access token + * @throws \RuntimeException if token exchange fails + */ + private function getOAuthAccessToken() + { + if ($this->oauthAccessToken !== null && microtime(true) < $this->oauthTokenExpiresAt) { + return $this->oauthAccessToken; + } + + $tokenUrl = $this->getHost() . '/oauth/token'; + + $client = new \GuzzleHttp\Client(); + try { + $response = $client->post($tokenUrl, [ + 'form_params' => [ + 'client_id' => $this->oauthClientId, + 'client_secret' => $this->oauthClientSecret, + ], + ]); + } catch (\GuzzleHttp\Exception\RequestException $e) { + throw new \RuntimeException('OAuth token exchange failed: ' . $e->getMessage()); + } + + $data = json_decode((string) $response->getBody(), true); + if (!isset($data['access_token'])) { + throw new \RuntimeException('OAuth token exchange failed: missing access_token in response'); + } + + $this->oauthAccessToken = $data['access_token']; + $expiresIn = (int)$data['expires_in']; + $this->oauthTokenExpiresAt = microtime(true) + ($expiresIn - 30); + + return $this->oauthAccessToken; + } + /** * Returns an array of host settings * From d07599f9f0801349364ac6deb35d00341155c2df Mon Sep 17 00:00:00 2001 From: Sancha Pereira Date: Fri, 15 May 2026 12:14:54 +0100 Subject: [PATCH 2/2] Refactor OnfidoTestCase setup to support OAuth --- .github/workflows/php.yml | 18 +++++++++++++++++- test/OnfidoTestCase.php | 21 ++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 219cb91..667060b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -37,7 +37,7 @@ jobs: uses: php-actions/composer@8a65f0d3c6a1d17ca4800491a40b5756a4c164f3 # v6 with: php_version: ${{ matrix.php-version }} - - name: Test with phpunit + - name: Test with API token auth if: ${{ matrix.php-version == '8.3' && github.repository_owner == 'onfido' && (github.event_name == 'pull_request' || @@ -52,6 +52,22 @@ jobs: ONFIDO_SAMPLE_VIDEO_ID_2: ${{ secrets.ONFIDO_SAMPLE_VIDEO_ID_2 }} ONFIDO_SAMPLE_MOTION_ID_1: ${{ secrets.ONFIDO_SAMPLE_MOTION_ID_1 }} ONFIDO_SAMPLE_MOTION_ID_2: ${{ secrets.ONFIDO_SAMPLE_MOTION_ID_2 }} + - name: Test with OAuth client credentials auth + if: ${{ matrix.php-version == '8.3' && + github.repository_owner == 'onfido' && + (github.event_name == 'pull_request' || + github.event_name == 'release' || + github.event_name == 'workflow_dispatch') }} + run: | + vendor/bin/phpunit + env: + ONFIDO_OAUTH_CLIENT_ID: ${{ secrets.ONFIDO_OAUTH_CLIENT_ID }} + ONFIDO_OAUTH_CLIENT_SECRET: ${{ secrets.ONFIDO_OAUTH_CLIENT_SECRET }} + ONFIDO_SAMPLE_APPLICANT_ID: ${{ secrets.ONFIDO_SAMPLE_APPLICANT_ID }} + ONFIDO_SAMPLE_VIDEO_ID_1: ${{ secrets.ONFIDO_SAMPLE_VIDEO_ID_1 }} + ONFIDO_SAMPLE_VIDEO_ID_2: ${{ secrets.ONFIDO_SAMPLE_VIDEO_ID_2 }} + ONFIDO_SAMPLE_MOTION_ID_1: ${{ secrets.ONFIDO_SAMPLE_MOTION_ID_1 }} + ONFIDO_SAMPLE_MOTION_ID_2: ${{ secrets.ONFIDO_SAMPLE_MOTION_ID_2 }} publish: runs-on: ubuntu-latest diff --git a/test/OnfidoTestCase.php b/test/OnfidoTestCase.php index e51675b..65390ae 100644 --- a/test/OnfidoTestCase.php +++ b/test/OnfidoTestCase.php @@ -17,15 +17,30 @@ abstract class OnfidoTestCase extends TestCase */ public static function setUpBeforeClass(): void { + $config = Onfido\Configuration::getDefaultConfiguration(); + + $oauthClientId = getenv('ONFIDO_OAUTH_CLIENT_ID'); + $basePath = getenv('ONFIDO_BASE_PATH'); + + if ($oauthClientId) { + $config->setOAuthCredentials($oauthClientId, getenv('ONFIDO_OAUTH_CLIENT_SECRET')); + } else { + $config->setApiToken(getenv('ONFIDO_API_TOKEN')); + } + + if ($basePath) { + $config->setHost($basePath); + } else { + $config->setRegion(Onfido\Region::EU); + } + self::$onfido = new Onfido\Api\DefaultApi( new \GuzzleHttp\Client([ 'timeout' => 30, 'connect_timeout' => 30, 'read_timeout' => 30 ]), - Onfido\Configuration::getDefaultConfiguration() - ->setApiToken(getenv('ONFIDO_API_TOKEN')) - ->setRegion(Onfido\Region::EU) + $config ); self::$sampleapplicant_id = getenv('ONFIDO_SAMPLE_APPLICANT_ID');