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 ;
@@ -486,14 +487,35 @@ public function code(string $state = '', string $code = '', string $scope = '',
486487 }
487488
488489 if ($ autoProvisionAllowed ) {
489- if (!$ softAutoProvisionAllowed && $ userFromOtherBackend !== null ) {
490- // if soft auto-provisioning is disabled,
491- // we refuse login for a user that already exists in another backend
492- $ message = $ this ->l10n ->t ('User conflict ' );
493- return $ this ->build403TemplateResponse ($ message , Http::STATUS_BAD_REQUEST , ['reason ' => 'non-soft auto provision, user conflict ' ], false );
490+ // $softAutoProvisionAllowed = (!isset($oidcSystemConfig['soft_auto_provision']) || $oidcSystemConfig['soft_auto_provision']);
491+ // if (!$softAutoProvisionAllowed && $userFromOtherBackend !== null) {
492+ // if soft auto-provisioning is disabled,
493+ // we refuse login for a user that already exists in another backend
494+ // $message = $this->l10n->t('User conflict');
495+ // return $this->build403TemplateResponse($message, Http::STATUS_BAD_REQUEST, ['reason' => 'non-soft auto provision, user conflict'], false);
496+ // }
497+
498+ // TODO: (proposal) refactor all provisioning strategies into event handlers
499+ $ user = null ;
500+
501+ try {
502+ $ user = $ this ->provisioningService ->provisionUser ($ userId , $ providerId , $ idTokenPayload , $ userFromOtherBackend );
503+ } catch (ProvisioningDeniedException $ denied ) {
504+ // TODO MagentaCLOUD should upstream the exception handling
505+ $ redirectUrl = $ denied ->getRedirectUrl ();
506+ if ($ redirectUrl === null ) {
507+ $ message = $ this ->l10n ->t ('Failed to provision user ' );
508+ return $ this ->build403TemplateResponse ($ message , Http::STATUS_BAD_REQUEST , ['reason ' => $ denied ->getMessage ()]);
509+ } else {
510+ // error response is a redirect, e.g. to a booking site
511+ // so that you can immediately get the registration page
512+ return new RedirectResponse ($ redirectUrl );
513+ }
494514 }
515+
495516 // use potential user from other backend, create it in our backend if it does not exist
496- $ user = $ this ->provisioningService ->provisionUser ($ userId , $ providerId , $ idTokenPayload , $ userFromOtherBackend );
517+ // $user = $this->provisioningService->provisionUser($userId, $providerId, $idTokenPayload, $userFromOtherBackend);
518+ // no default exception handling to pass on unittest assertion failures
497519 } else {
498520 // when auto provision is disabled, we assume the user has been created by another user backend (or manually)
499521 $ user = $ userFromOtherBackend ;
@@ -518,17 +540,6 @@ public function code(string $state = '', string $code = '', string $scope = '',
518540 $ this ->eventDispatcher ->dispatchTyped (new UserLoggedInEvent ($ user , $ user ->getUID (), null , false ));
519541 }
520542
521- $ tokenExchangeEnabled = (isset ($ oidcSystemConfig ['token_exchange ' ]) && $ oidcSystemConfig ['token_exchange ' ] === true );
522- if ($ tokenExchangeEnabled ) {
523- // store all token information for potential token exchange requests
524- $ tokenData = array_merge (
525- $ data ,
526- ['provider_id ' => $ providerId ],
527- );
528- $ this ->tokenService ->storeToken ($ tokenData );
529- }
530- $ this ->config ->setUserValue ($ user ->getUID (), Application::APP_ID , 'had_token_once ' , '1 ' );
531-
532543 // Set last password confirm to the future as we don't have passwords to confirm against with SSO
533544 $ this ->session ->set ('last-password-confirm ' , strtotime ('+4 year ' , time ()));
534545
@@ -764,7 +775,7 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
764775 * @return JSONResponse
765776 */
766777 private function getBackchannelLogoutErrorResponse (
767- string $ error , string $ description , array $ throttleMetadata = [],
778+ string $ error , string $ description , array $ throttleMetadata = [], ? bool $ throttle = null ,
768779 ): JSONResponse {
769780 $ this ->logger ->debug ('Backchannel logout error. ' . $ error . ' ; ' . $ description );
770781 return new JSONResponse (
0 commit comments