Skip to content

Commit d2cb2ae

Browse files
authored
Merge pull request #1149 from andreblanke/feat/nested-group-claim
Support nested claim mapping for groups attribute
2 parents 999a79e + f0ca12d commit d2cb2ae

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

lib/Service/ProvisioningService.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public function hasOidcUserProvisitioned(string $userId): bool {
6262

6363
/**
6464
* Resolves a claim path like "custom.nickname" or multiple alternatives separated by "|".
65-
* Returns the first found string value, or null if none could be resolved.
65+
* Returns the first found value, or null if none could be resolved.
6666
*/
67-
public function getClaimValue(object|array $tokenPayload, string $claimPath, int $providerId): mixed {
67+
public function getClaimValues(object|array $tokenPayload, string $claimPath, int $providerId): mixed {
6868
if ($claimPath === '') {
6969
return null;
7070
}
@@ -99,14 +99,21 @@ public function getClaimValue(object|array $tokenPayload, string $claimPath, int
9999
}
100100
}
101101

102-
if (is_string($value)) {
103-
return $value;
104-
}
102+
return $value;
105103
}
106104

107105
return null;
108106
}
109107

108+
/**
109+
* Resolves a claim path like "custom.nickname" or multiple alternatives separated by "|".
110+
* Returns the first found string value, or null if none could be resolved.
111+
*/
112+
public function getClaimValue(object|array $tokenPayload, string $claimPath, int $providerId): mixed {
113+
$value = $this->getClaimValues($tokenPayload, $claimPath, $providerId);
114+
return is_string($value) ? $value : null;
115+
}
116+
110117
/**
111118
* @param string $tokenUserId
112119
* @param int $providerId
@@ -523,7 +530,7 @@ private function setUserAvatar(string $userId, string $avatarAttribute): void {
523530

524531
public function getSyncGroupsOfToken(int $providerId, object $idTokenPayload) {
525532
$groupsAttribute = $this->providerService->getSetting($providerId, ProviderService::SETTING_MAPPING_GROUPS, 'groups');
526-
$groupsData = $idTokenPayload->{$groupsAttribute} ?? null;
533+
$groupsData = $this->getClaimValues($idTokenPayload, $groupsAttribute, $providerId);
527534

528535
$groupsWhitelistRegex = $this->getGroupWhitelistRegex($providerId);
529536

tests/unit/Service/ProvisioningServiceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ public function testProvisionUserGroups(string $gid, string $displayName, object
360360
[
361361
[$providerId, ProviderService::SETTING_GROUP_WHITELIST_REGEX, '', $group_whitelist],
362362
[$providerId, ProviderService::SETTING_MAPPING_GROUPS, 'groups', 'groups'],
363+
[$providerId, ProviderService::SETTING_RESOLVE_NESTED_AND_FALLBACK_CLAIMS_MAPPING, '0', '0'],
363364
]
364365
));
365366

0 commit comments

Comments
 (0)