1313use OCA \UserOIDC \Db \UserMapper ;
1414use OCA \UserOIDC \Event \AttributeMappedEvent ;
1515use OCP \Accounts \IAccountManager ;
16+ use OCP \Accounts \PropertyDoesNotExistException ;
1617use OCP \AppFramework \Db \DoesNotExistException ;
1718use OCP \AppFramework \Db \MultipleObjectsReturnedException ;
1819use OCP \DB \Exception ;
2627use OCP \IUser ;
2728use OCP \IUserManager ;
2829use OCP \L10N \IFactory ;
30+ use OCP \PreConditionNotMetException ;
2931use OCP \User \Events \UserChangedEvent ;
3032use Psr \Log \LoggerInterface ;
3133use Throwable ;
@@ -104,15 +106,18 @@ public function getClaimValue(object|array $tokenPayload, string $claimPath, int
104106
105107 return null ;
106108 }
109+
107110 /**
108111 * @param string $tokenUserId
109112 * @param int $providerId
110113 * @param object $idTokenPayload
111114 * @param IUser|null $existingLocalUser
112- * @return IUser|null
115+ * @return array{user: ? IUser, userData: array}
113116 * @throws Exception
117+ * @throws PropertyDoesNotExistException
118+ * @throws PreConditionNotMetException
114119 */
115- public function provisionUser (string $ tokenUserId , int $ providerId , object $ idTokenPayload , ?IUser $ existingLocalUser = null ): ? IUser {
120+ public function provisionUser (string $ tokenUserId , int $ providerId , object $ idTokenPayload , ?IUser $ existingLocalUser = null ): array {
116121 // user data potentially later used by globalsiteselector if user_oidc is used with global scale
117122 $ oidcGssUserData = get_object_vars ($ idTokenPayload );
118123
@@ -191,15 +196,21 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
191196 $ isUserCreationDisabled = isset ($ oidcSystemConfig ['disable_account_creation ' ])
192197 && in_array ($ oidcSystemConfig ['disable_account_creation ' ], [true , 'true ' , 1 , '1 ' ], true );
193198 if ($ isUserCreationDisabled ) {
194- return null ;
199+ return [
200+ 'user ' => null ,
201+ 'userData ' => $ oidcGssUserData ,
202+ ];
195203 }
196204
197205 $ backendUser = $ this ->userMapper ->getOrCreate ($ providerId , $ event ->getValue () ?? '' );
198206 $ this ->logger ->debug ('User obtained from the OIDC user backend: ' . $ backendUser ->getUserId ());
199207
200208 $ user = $ this ->userManager ->get ($ backendUser ->getUserId ());
201209 if ($ user === null ) {
202- return null ;
210+ return [
211+ 'user ' => null ,
212+ 'userData ' => $ oidcGssUserData ,
213+ ];
203214 }
204215 }
205216
@@ -413,8 +424,6 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
413424 $ account ->setProperty ('gender ' , $ event ->getValue (), $ fallbackScope , '1 ' , '' );
414425 }
415426
416- $ this ->session ->set ('user_oidc.oidcUserData ' , $ oidcGssUserData );
417-
418427 while (true ) {
419428 try {
420429 $ this ->accountManager ->updateAccount ($ account );
@@ -432,7 +441,10 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
432441 throw $ e ;
433442 }
434443 }
435- return $ user ;
444+ return [
445+ 'user ' => $ user ,
446+ 'userData ' => $ oidcGssUserData ,
447+ ];
436448 }
437449
438450 /**
0 commit comments