3636use OCA \UserOIDC \Service \DiscoveryService ;
3737use OCA \UserOIDC \Service \LdapService ;
3838use OCA \UserOIDC \Service \ProviderService ;
39+ use OCA \UserOIDC \Service \EventProvisioningService ;
40+ use OCA \UserOIDC \Service \ProvisioningDeniedException ;
3941use OCA \UserOIDC \Service \ProvisioningService ;
4042use OCA \UserOIDC \Vendor \Firebase \JWT \JWT ;
4143use OCA \UserOIDC \AppInfo \Application ;
@@ -118,6 +120,9 @@ class LoginController extends BaseOidcController {
118120 /** @var SessionMapper */
119121 private $ sessionMapper ;
120122
123+ /** @var EventProvisioningService */
124+ private $ eventProvisioningService ;
125+
121126 /** @var ProvisioningService */
122127 private $ provisioningService ;
123128
@@ -145,6 +150,7 @@ public function __construct(
145150 IConfig $ config ,
146151 IProvider $ authTokenProvider ,
147152 SessionMapper $ sessionMapper ,
153+ EventProvisioningService $ eventProvisioningService ,
148154 ProvisioningService $ provisioningService ,
149155 IL10N $ l10n ,
150156 ILogger $ logger ,
@@ -168,6 +174,7 @@ public function __construct(
168174 $ this ->ldapService = $ ldapService ;
169175 $ this ->authTokenProvider = $ authTokenProvider ;
170176 $ this ->sessionMapper = $ sessionMapper ;
177+ $ this ->eventProvisioningService = $ eventProvisioningService ;
171178 $ this ->provisioningService = $ provisioningService ;
172179 $ this ->request = $ request ;
173180 $ this ->l10n = $ l10n ;
@@ -471,10 +478,29 @@ public function code(string $state = '', string $code = '', string $scope = '',
471478 }
472479
473480 $ oidcSystemConfig = $ this ->config ->getSystemValue ('user_oidc ' , []);
481+ $ eventProvisionAllowed = (!isset ($ oidcSystemConfig ['event_provision ' ]) || $ oidcSystemConfig ['event_provision ' ]);
474482 $ autoProvisionAllowed = (!isset ($ oidcSystemConfig ['auto_provision ' ]) || $ oidcSystemConfig ['auto_provision ' ]);
475483
476484 // Provisioning
477- if ($ autoProvisionAllowed ) {
485+ if ($ eventProvisionAllowed ) {
486+ // for the moment, make event provisioning another (prio) config option
487+ // TODO: (proposal) refactor all provisioning strategies into event handlers
488+ try {
489+ $ user = $ this ->eventProvisioningService ->provisionUser ($ userId , $ providerId , $ idTokenPayload );
490+ } catch (ProvisioningDeniedException $ denied ) {
491+ $ redirectUrl = $ denied ->getRedirectUrl ();
492+ if ($ redirectUrl === null ) {
493+ $ message = $ this ->l10n ->t ('Failed to provision the user ' );
494+ return $ this ->build403TemplateResponse ($ message , Http::STATUS_BAD_REQUEST , ['reason ' => $ denied ->getMessage ()]);
495+ } else {
496+ // error response is a redirect, e.g. to a booking site
497+ // so that you can immediately get the registration page
498+ return new RedirectResponse ($ redirectUrl );
499+ }
500+ } catch (\Exception $ e ) {
501+ $ user = null ;
502+ }
503+ } elseif ($ autoProvisionAllowed ) {
478504 $ user = $ this ->provisioningService ->provisionUser ($ userId , $ providerId , $ idTokenPayload );
479505 } else {
480506 // in case user is provisioned by user_ldap, userManager->search() triggers an ldap search which syncs the results
@@ -563,7 +589,8 @@ public function singleLogoutService() {
563589 $ endSessionEndpoint .= '&client_id= ' . $ provider ->getClientId ();
564590 $ shouldSendIdToken = $ this ->providerService ->getSetting (
565591 $ provider ->getId (),
566- ProviderService::SETTING_SEND_ID_TOKEN_HINT , '0 '
592+ ProviderService::SETTING_SEND_ID_TOKEN_HINT ,
593+ '0 '
567594 ) === '1 ' ;
568595 $ idToken = $ this ->session ->get (self ::ID_TOKEN );
569596 if ($ shouldSendIdToken && $ idToken ) {
@@ -712,8 +739,12 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
712739 * @param bool|null $throttle
713740 * @return JSONResponse
714741 */
715- private function getBackchannelLogoutErrorResponse (string $ error , string $ description ,
716- array $ throttleMetadata = [], ?bool $ throttle = null ): JSONResponse {
742+ private function getBackchannelLogoutErrorResponse (
743+ string $ error ,
744+ string $ description ,
745+ array $ throttleMetadata = [],
746+ ?bool $ throttle = null
747+ ): JSONResponse {
717748 $ this ->logger ->debug ('Backchannel logout error. ' . $ error . ' ; ' . $ description );
718749 $ response = new JSONResponse (
719750 [
0 commit comments