1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2026-01-03 23:42:28 +03:00

OIDC Userinfo: Started writing tests to cover userinfo calling

This commit is contained in:
Dan Brown
2024-04-17 23:24:57 +01:00
parent 7d7cd32ca7
commit fa543bbd4d
4 changed files with 111 additions and 46 deletions

View File

@@ -53,7 +53,7 @@ class OidcProviderSettings
*/
protected function validateInitial(): void
{
$required = ['clientId', 'clientSecret', 'redirectUri', 'issuer'];
$required = ['clientId', 'clientSecret', 'issuer'];
foreach ($required as $prop) {
if (empty($this->$prop)) {
throw new InvalidArgumentException("Missing required configuration \"{$prop}\" value");

View File

@@ -201,6 +201,9 @@ class OidcService
if (empty($userDetails->email)) {
throw new OidcException(trans('errors.oidc_no_email_address'));
}
if (empty($userDetails->name)) {
$userDetails->name = $userDetails->externalId;
}
$isLoggedIn = auth()->check();
if ($isLoggedIn) {

View File

@@ -28,7 +28,7 @@ class OidcUserDetails
}
/**
* Populate user details from OidcIdToken data.
* Populate user details from the given claim data.
*/
public function populate(
ProvidesClaims $claims,
@@ -38,11 +38,11 @@ class OidcUserDetails
): void {
$this->externalId = $claims->getClaim($idClaim) ?? $this->externalId;
$this->email = $claims->getClaim('email') ?? $this->email;
$this->name = static::getUserDisplayName($displayNameClaims, $claims, $this->externalId) ?? $this->name;
$this->name = static::getUserDisplayName($displayNameClaims, $claims) ?? $this->name;
$this->groups = static::getUserGroups($groupsClaim, $claims) ?? $this->groups;
}
protected static function getUserDisplayName(string $displayNameClaims, ProvidesClaims $token, string $defaultValue): string
protected static function getUserDisplayName(string $displayNameClaims, ProvidesClaims $token): string
{
$displayNameClaimParts = explode('|', $displayNameClaims);
@@ -54,10 +54,6 @@ class OidcUserDetails
}
}
if (count($displayName) === 0) {
$displayName[] = $defaultValue;
}
return implode(' ', $displayName);
}