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 ;
@@ -500,14 +501,31 @@ public function code(string $state = '', string $code = '', string $scope = '',
500501 }
501502
502503 if ($ autoProvisionAllowed ) {
503- if (!$ softAutoProvisionAllowed && $ userFromOtherBackend !== null ) {
504+ // TODO: (proposal) refactor all provisioning strategies into event handlers
505+ $ user = null ;
506+
507+ try {
508+ // use potential user from other backend, create it in our backend if it does not exist
509+ $ user = $ this ->provisioningService ->provisionUser ($ userId , $ providerId , $ idTokenPayload , $ userFromOtherBackend );
510+ } catch (ProvisioningDeniedException $ denied ) {
511+ // TODO: MagentaCLOUD should upstream the exception handling
512+ $ redirectUrl = $ denied ->getRedirectUrl ();
513+ if ($ redirectUrl === null ) {
514+ $ message = $ this ->l10n ->t ('Failed to provision user ' );
515+ return $ this ->build403TemplateResponse ($ message , Http::STATUS_BAD_REQUEST , ['reason ' => $ denied ->getMessage ()]);
516+ } else {
517+ // error response is a redirect, e.g. to a booking site
518+ // so that you can immediately get the registration page
519+ return new RedirectResponse ($ redirectUrl );
520+ }
521+ }
522+
523+ if (!$ softAutoProvisionAllowed && $ userFromOtherBackend !== null && $ user === null ) {
504524 // if soft auto-provisioning is disabled,
505525 // we refuse login for a user that already exists in another backend
506526 $ message = $ this ->l10n ->t ('User conflict ' );
507527 return $ this ->build403TemplateResponse ($ message , Http::STATUS_BAD_REQUEST , ['reason ' => 'non-soft auto provision, user conflict ' ], false );
508528 }
509- // use potential user from other backend, create it in our backend if it does not exist
510- $ user = $ this ->provisioningService ->provisionUser ($ userId , $ providerId , $ idTokenPayload , $ userFromOtherBackend );
511529 } else {
512530 // when auto provision is disabled, we assume the user has been created by another user backend (or manually)
513531 $ user = $ userFromOtherBackend ;
@@ -806,7 +824,7 @@ public function telekomBackChannelLogout(string $logout_token = '') {
806824 * @return JSONResponse
807825 */
808826 private function getBackchannelLogoutErrorResponse (
809- string $ error , string $ description , array $ throttleMetadata = [],
827+ string $ error , string $ description , array $ throttleMetadata = [], ? bool $ throttle = null ,
810828 ): JSONResponse {
811829 $ this ->logger ->debug ('Backchannel logout error. ' . $ error . ' ; ' . $ description );
812830 return new JSONResponse (
@@ -827,4 +845,4 @@ private function toCodeChallenge(string $data): string {
827845 $ s = str_replace ('/ ' , '_ ' , $ s ); // 63rd char of encoding
828846 return $ s ;
829847 }
830- }
848+ }
0 commit comments