2323use OCA \UserOIDC \Service \DiscoveryService ;
2424use OCA \UserOIDC \Service \LdapService ;
2525use OCA \UserOIDC \Service \ProviderService ;
26+ use OCA \UserOIDC \Service \ProvisioningDeniedException ;
2627use OCA \UserOIDC \Service \ProvisioningService ;
2728use OCA \UserOIDC \Service \TokenService ;
2829use OCA \UserOIDC \User \Backend ;
@@ -491,14 +492,35 @@ public function code(string $state = '', string $code = '', string $scope = '',
491492 }
492493
493494 if ($ autoProvisionAllowed ) {
494- if (!$ softAutoProvisionAllowed && $ userFromOtherBackend !== null ) {
495- // if soft auto-provisioning is disabled,
496- // we refuse login for a user that already exists in another backend
497- $ message = $ this ->l10n ->t ('User conflict ' );
498- return $ this ->build403TemplateResponse ($ message , Http::STATUS_BAD_REQUEST , ['reason ' => 'non-soft auto provision, user conflict ' ], false );
495+ // $softAutoProvisionAllowed = (!isset($oidcSystemConfig['soft_auto_provision']) || $oidcSystemConfig['soft_auto_provision']);
496+ // if (!$softAutoProvisionAllowed && $userFromOtherBackend !== null) {
497+ // if soft auto-provisioning is disabled,
498+ // we refuse login for a user that already exists in another backend
499+ // $message = $this->l10n->t('User conflict');
500+ // return $this->build403TemplateResponse($message, Http::STATUS_BAD_REQUEST, ['reason' => 'non-soft auto provision, user conflict'], false);
501+ // }
502+
503+ // TODO: (proposal) refactor all provisioning strategies into event handlers
504+ $ user = null ;
505+
506+ try {
507+ $ user = $ this ->provisioningService ->provisionUser ($ userId , $ providerId , $ idTokenPayload , $ userFromOtherBackend );
508+ } catch (ProvisioningDeniedException $ denied ) {
509+ // TODO MagentaCLOUD should upstream the exception handling
510+ $ redirectUrl = $ denied ->getRedirectUrl ();
511+ if ($ redirectUrl === null ) {
512+ $ message = $ this ->l10n ->t ('Failed to provision user ' );
513+ return $ this ->build403TemplateResponse ($ message , Http::STATUS_BAD_REQUEST , ['reason ' => $ denied ->getMessage ()]);
514+ } else {
515+ // error response is a redirect, e.g. to a booking site
516+ // so that you can immediately get the registration page
517+ return new RedirectResponse ($ redirectUrl );
518+ }
499519 }
520+
500521 // use potential user from other backend, create it in our backend if it does not exist
501- $ user = $ this ->provisioningService ->provisionUser ($ userId , $ providerId , $ idTokenPayload , $ userFromOtherBackend );
522+ // $user = $this->provisioningService->provisionUser($userId, $providerId, $idTokenPayload, $userFromOtherBackend);
523+ // no default exception handling to pass on unittest assertion failures
502524 } else {
503525 // when auto provision is disabled, we assume the user has been created by another user backend (or manually)
504526 $ user = $ userFromOtherBackend ;
@@ -523,16 +545,16 @@ public function code(string $state = '', string $code = '', string $scope = '',
523545 $ this ->eventDispatcher ->dispatchTyped (new UserLoggedInEvent ($ user , $ user ->getUID (), null , false ));
524546 }
525547
526- $ tokenExchangeEnabled = (isset ($ oidcSystemConfig ['token_exchange ' ]) && $ oidcSystemConfig ['token_exchange ' ] === true );
527- if ($ tokenExchangeEnabled ) {
528- // store all token information for potential token exchange requests
529- $ tokenData = array_merge (
530- $ data ,
531- ['provider_id ' => $ providerId ],
532- );
533- $ this ->tokenService ->storeToken ($ tokenData );
534- }
535- $ this ->config ->setUserValue ($ user ->getUID (), Application::APP_ID , 'had_token_once ' , '1 ' );
548+ // $tokenExchangeEnabled = (isset($oidcSystemConfig['token_exchange']) && $oidcSystemConfig['token_exchange'] === true);
549+ // if ($tokenExchangeEnabled) {
550+ // store all token information for potential token exchange requests
551+ // $tokenData = array_merge(
552+ // $data,
553+ // ['provider_id' => $providerId],
554+ // );
555+ // $this->tokenService->storeToken($tokenData);
556+ // }
557+ // $this->config->setUserValue($user->getUID(), Application::APP_ID, 'had_token_once', '1');
536558
537559 // Set last password confirm to the future as we don't have passwords to confirm against with SSO
538560 $ this ->session ->set ('last-password-confirm ' , strtotime ('+4 year ' , time ()));
@@ -769,7 +791,7 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
769791 * @return JSONResponse
770792 */
771793 private function getBackchannelLogoutErrorResponse (
772- string $ error , string $ description , array $ throttleMetadata = [],
794+ string $ error , string $ description , array $ throttleMetadata = [], ? bool $ throttle = null ,
773795 ): JSONResponse {
774796 $ this ->logger ->debug ('Backchannel logout error. ' . $ error . ' ; ' . $ description );
775797 return new JSONResponse (
0 commit comments