Skip to content

Commit 1f88b29

Browse files
authored
Merge pull request #1041 from nextcloud/enh/1034/userinfo-data-for-provisioning
Call userinfo on login to enrich the login ID token
2 parents b722cc2 + 8f1eb93 commit 1f88b29

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ To change this behaviour and disable the default claims, you can change this val
8686
When default claims are disabled, each claim will be asked for only if there is an attribute explicitely mapped
8787
in the OpenId client settings (in Nextcloud's admin settings).
8888

89+
### Call the userinfo endpoint to enrich the login ID token
90+
91+
If some user information is not in your login ID tokens but can be obtained with the userinfo endpoint, just enable
92+
`enrich_login_id_token_with_userinfo` in config.php. This is disabled by default.
93+
``` php
94+
'user_oidc' => [
95+
'enrich_login_id_token_with_userinfo' => true,
96+
],
97+
```
98+
99+
This will use the content of the userinfo endpoint response just like if it had been included in the login ID token.
100+
101+
This will only work on login and not when validating a bearer token
102+
because provisioning when validating a bearer access token is not supported yet.
103+
89104
### ID4me option
90105
ID4me is an application setting switch which is configurable as normal Nextcloud app setting:
91106
```

lib/Controller/LoginController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use OCA\UserOIDC\Event\TokenObtainedEvent;
2323
use OCA\UserOIDC\Service\DiscoveryService;
2424
use OCA\UserOIDC\Service\LdapService;
25+
use OCA\UserOIDC\Service\OIDCService;
2526
use OCA\UserOIDC\Service\ProviderService;
2627
use OCA\UserOIDC\Service\ProvisioningService;
2728
use OCA\UserOIDC\Service\TokenService;
@@ -85,6 +86,7 @@ public function __construct(
8586
private LoggerInterface $logger,
8687
private ICrypto $crypto,
8788
private TokenService $tokenService,
89+
private OidcService $oidcService,
8890
) {
8991
parent::__construct($request, $config);
9092
}
@@ -426,6 +428,17 @@ public function code(string $state = '', string $code = '', string $scope = '',
426428
$idTokenPayload = JWT::decode($idTokenRaw, $jwks);
427429
}
428430

431+
// default is false
432+
if (isset($oidcSystemConfig['enrich_login_id_token_with_userinfo']) && $oidcSystemConfig['enrich_login_id_token_with_userinfo']) {
433+
$userInfo = $this->oidcService->userInfo($provider, $data['access_token']);
434+
foreach ($userInfo as $key => $value) {
435+
// give priority to id token values, only use userinfo ones if missing in id token
436+
if (!isset($idTokenPayload->{$key})) {
437+
$idTokenPayload->{$key} = $value;
438+
}
439+
}
440+
}
441+
429442
$this->logger->debug('Parsed the JWT payload: ' . json_encode($idTokenPayload, JSON_THROW_ON_ERROR));
430443

431444
if ($idTokenPayload->exp < $this->timeFactory->getTime()) {

0 commit comments

Comments
 (0)