A free open source IT asset/license management system
Fixed #20006 - SCIM Users groups[].value is returned as an integer, causing authentik user discovery to fail
snipe946873a44fc3
diff --git a/app/Models/SnipeSCIMConfig.php b/app/Models/SnipeSCIMConfig.phpindex 1d4487f772..b32f2143ca 100644--- a/app/Models/SnipeSCIMConfig.php+++ b/app/Models/SnipeSCIMConfig.php@@ -248,7 +248,7 @@ class SnipeRootComplex extends Complex{if ($path !== null && $path->isNotEmpty() && $this->parent === null) {$valuePathAttributes = $path->getValuePathAttributes();- if (!empty($valuePathAttributes) && $this->getSubNode($valuePathAttributes[0]) === null) {+ if (! empty($valuePathAttributes) && $this->getSubNode($valuePathAttributes[0]) === null) {$attrName = $valuePathAttributes[0];$attribute = null;@@ -1054,7 +1054,17 @@ class SnipeSCIMConfigeloquent('title', 'jobtitle'),eloquent('preferredLanguage', 'locale'),(new Collection('groups'))->withSubAttributes(- eloquent('value', 'id'),+ (new class('value', 'id') extends Eloquent+ {+ // RFC 7643 §4.1.2 defines groups[].value as a+ // string.+ protected function doRead(&$object, $attributes = [])+ {+ $value = parent::doRead($object, $attributes);++ return $value === null ? null : (string) $value;+ }+ }),(new class('$ref') extends Eloquent{protected function doRead(&$object, $attributes = [])diff --git a/tests/Feature/Scim/ScimGroupValueStringTypeTest.php b/tests/Feature/Scim/ScimGroupValueStringTypeTest.phpnew file mode 100644index 0000000000..dad6d6e01b--- /dev/null+++ b/tests/Feature/Scim/ScimGroupValueStringTypeTest.php@@ -0,0 +1,59 @@+<?php++namespace Tests\Feature\Scim;++use App\Models\Group;+use App\Models\User;+use Laravel\Passport\Passport;+use Tests\TestCase;++/**+ * RFC 7643 §4.1.2 defines the `value` sub-attribute of SCIM multi-valued+ * complex types as a string. Strict clients (authentik, Okta in some+ * modes) reject the integer form. These regression tests pin both+ * directions. Users resource's groups[].value and Groups resource's+ * members[].value must both serialize as strings, since a sibling fix+ * on only one direction leaves the other as a silent integration-breaker+ * for the next client that validates the response shape.+ *+ * Groups.members[].value regression: #19996 / PR #20005.+ * Users.groups[].value regression: #20006.+ */+class ScimGroupValueStringTypeTest extends TestCase+{+ public function test_users_resource_returns_groups_value_as_string(): void+ {+ Passport::actingAs(User::factory()->superuser()->create());++ $group = Group::factory()->create();+ $user = User::factory()->create();+ $user->groups()->attach($group->id);++ $response = $this->getJson('/scim/v2/Users/'.$user->id);++ $response->assertStatus(200);++ $groups = $response->json('groups');+ $this->assertNotEmpty($groups, 'User should list at least one group.');+ $this->assertIsString($groups[0]['value'], 'groups[].value must be a string per RFC 7643.');+ $this->assertSame((string) $group->id, $groups[0]['value']);+ }++ public function test_groups_resource_returns_members_value_as_string(): void+ {+ Passport::actingAs(User::factory()->superuser()->create());++ $group = Group::factory()->create();+ $user = User::factory()->create();+ $group->users()->attach($user->id);++ $response = $this->getJson('/scim/v2/Groups/'.$group->id);++ $response->assertStatus(200);++ $members = $response->json('members');+ $this->assertNotEmpty($members, 'Group should list at least one member.');+ $this->assertIsString($members[0]['value'], 'members[].value must be a string per RFC 7643.');+ $this->assertSame((string) $user->id, $members[0]['value']);+ }+}