Skip to content

Commit e4a1230

Browse files
CopilotSubterrane
andcommitted
Fix handleDataResponse and model constructors for otp_devices API compatibility
Co-authored-by: Subterrane <5290140+Subterrane@users.noreply.github.com>
1 parent a0757a0 commit e4a1230

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/OneLoginClient.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,13 @@ protected function handleDataResponse($response)
285285
if (property_exists($content, 'data')) {
286286
$data = $content->data;
287287
}
288-
if (count($data) == 1 && empty($data[0])) {
288+
289+
// Handle case where API returns object instead of array (e.g., otp_devices endpoint)
290+
if (is_object($data)) {
291+
return $data;
292+
}
293+
294+
if (is_array($data) && count($data) == 1 && empty($data[0])) {
289295
return [];
290296
}
291297

src/models/AuthFactor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AuthFactor
1616
public function __construct($data)
1717
{
1818
$this->id = isset($data->factor_id)? (int) $data->factor_id : null;
19-
$this->name = $data->name;
19+
$this->name = $data->name ?? '';
2020
}
2121

2222
public function getId()

src/models/OTPDevice.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ class OTPDevice
3737
public function __construct($data)
3838
{
3939
$this->id = isset($data->id)? (int) $data->id : null;
40-
$this->active = $data->active;
41-
$this->default = $data->default;
42-
$this->authFactorName = $data->auth_factor_name;
43-
$this->phoneNumber = $data->phone_number;
44-
$this->typeDisplayName = $data->type_display_name;
45-
$this->needsTrigger = $data->needs_trigger;
46-
$this->userDisplayName = $data->user_display_name;
47-
$this->stateToken = $data->state_token;
40+
$this->active = $data->active ?? '';
41+
$this->default = $data->default ?? '';
42+
$this->authFactorName = $data->auth_factor_name ?? '';
43+
$this->phoneNumber = $data->phone_number ?? '';
44+
$this->typeDisplayName = $data->type_display_name ?? '';
45+
$this->needsTrigger = $data->needs_trigger ?? '';
46+
$this->userDisplayName = $data->user_display_name ?? '';
47+
$this->stateToken = $data->state_token ?? '';
4848
}
4949
}

0 commit comments

Comments
 (0)