3 namespace BookStack\Access\Oidc;
5 use Illuminate\Support\Arr;
9 public function __construct(
10 public ?string $externalId = null,
11 public ?string $email = null,
12 public ?string $name = null,
13 public ?array $groups = null,
14 public ?string $picture = null,
19 * Check if the user details are fully populated for our usage.
21 public function isFullyPopulated(bool $groupSyncActive): bool
23 $hasEmpty = empty($this->externalId)
24 || empty($this->email)
26 || ($groupSyncActive && $this->groups === null);
32 * Populate user details from the given claim data.
34 public function populate(
35 ProvidesClaims $claims,
37 string $displayNameClaims,
40 $this->externalId = $claims->getClaim($idClaim) ?? $this->externalId;
41 $this->email = $claims->getClaim('email') ?? $this->email;
42 $this->name = static::getUserDisplayName($displayNameClaims, $claims) ?? $this->name;
43 $this->groups = static::getUserGroups($groupsClaim, $claims) ?? $this->groups;
44 $this->picture = $claims->getClaim('picture') ?: $this->picture;
47 protected static function getUserDisplayName(string $displayNameClaims, ProvidesClaims $token): string
49 $displayNameClaimParts = explode('|', $displayNameClaims);
52 foreach ($displayNameClaimParts as $claim) {
53 $component = $token->getClaim(trim($claim)) ?? '';
54 if ($component !== '') {
55 $displayName[] = $component;
59 return implode(' ', $displayName);
62 protected static function getUserGroups(string $groupsClaim, ProvidesClaims $token): ?array
64 if (empty($groupsClaim)) {
68 $groupsList = Arr::get($token->getAllClaims(), $groupsClaim);
69 if (!is_array($groupsList)) {
73 return array_values(array_filter($groupsList, function ($val) {
74 return is_string($val);