Skip to content

Commit

Permalink
Add given_name and family_name claims to UserInfo
Browse files Browse the repository at this point in the history
The name splitting is using what was already implemented in nc for the
system address book
  • Loading branch information
ThoFrank committed Dec 23, 2024
1 parent 15b808e commit 37db1a5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/Controller/UserInfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCA\OIDCIdentityProvider\Db\ClientMapper;
use OCA\OIDCIdentityProvider\Exceptions\AccessTokenNotFoundException;
use OCA\OIDCIdentityProvider\Exceptions\ClientNotFoundException;
use OCA\DAV\CardDAV\Converter;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
Expand All @@ -40,6 +41,7 @@
use OCP\IUserManager;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\Server;
use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountProperty;
use OCP\Accounts\IAccountManager;
Expand Down Expand Up @@ -69,6 +71,8 @@ class UserInfoController extends ApiController
private $appConfig;
/** @var LoggerInterface */
private $logger;
/** @var Converter */
private $converter;

public function __construct(
string $appName,
Expand All @@ -94,6 +98,7 @@ public function __construct(
$this->accountManager = $accountManager;
$this->appConfig = $appConfig;
$this->logger = $logger;
$this->converter = Server::get(Converter::class);
}

/**
Expand Down Expand Up @@ -200,8 +205,14 @@ public function getInfo(): JSONResponse
'updated_at' => $user->getLastLogin(),
];
if ($account->getProperty(\OCP\Accounts\IAccountManager::PROPERTY_DISPLAYNAME)->getValue() != '') {
$profile = array_merge($profile,
['name' => $account->getProperty(\OCP\Accounts\IAccountManager::PROPERTY_DISPLAYNAME)->getValue()]);
$displayName = $account->getProperty(\OCP\Accounts\IAccountManager::PROPERTY_DISPLAYNAME)->getValue();
$names = $this->converter->splitFullName($displayName);
$profile = array_merge($profile, [
'name' => $displayName,
'family_name' => $names[0],
'given_name' => $names[1],
'middle_name' => $names[2]
]);
} else {
$profile = array_merge($profile, ['name' => $user->getDisplayName()]);
}
Expand All @@ -226,9 +237,6 @@ public function getInfo(): JSONResponse
}
}
// Possible further values
// 'family_name' => ,
// 'given_name' => ,
// 'middle_name' => ,
// 'nickname' => ,
// 'profile' => ,
// 'picture' => ,
Expand Down

0 comments on commit 37db1a5

Please sign in to comment.