|
36 | 36 | use OCA\UserOIDC\Service\DiscoveryService; |
37 | 37 | use OCA\UserOIDC\Service\LdapService; |
38 | 38 | use OCA\UserOIDC\Service\ProviderService; |
| 39 | +use OCA\UserOIDC\Service\EventProvisioningService; |
| 40 | +use OCA\UserOIDC\Service\ProvisioningDeniedException; |
39 | 41 | use OCA\UserOIDC\Service\ProvisioningService; |
40 | 42 | use OCA\UserOIDC\Vendor\Firebase\JWT\JWT; |
41 | 43 | use OCA\UserOIDC\AppInfo\Application; |
@@ -118,6 +120,9 @@ class LoginController extends BaseOidcController { |
118 | 120 | /** @var SessionMapper */ |
119 | 121 | private $sessionMapper; |
120 | 122 |
|
| 123 | + /** @var EventProvisioningService */ |
| 124 | + private $eventProvisioningService; |
| 125 | + |
121 | 126 | /** @var ProvisioningService */ |
122 | 127 | private $provisioningService; |
123 | 128 |
|
@@ -475,7 +480,23 @@ public function code(string $state = '', string $code = '', string $scope = '', |
475 | 480 |
|
476 | 481 | // Provisioning |
477 | 482 | if ($autoProvisionAllowed) { |
478 | | - $user = $this->provisioningService->provisionUser($userId, $providerId, $idTokenPayload); |
| 483 | + // TODO: (proposal) refactor all provisioning strategies into event handlers |
| 484 | + $user = null; |
| 485 | + try { |
| 486 | + $user = $this->provisioningService->provisionUser($userId, $providerId, $idTokenPayload); |
| 487 | + } catch (ProvisioningDeniedException $denied) { |
| 488 | + // TODO MagentaCLOUD should upstream the exception handling |
| 489 | + $redirectUrl = $denied->getRedirectUrl(); |
| 490 | + if ($redirectUrl === null) { |
| 491 | + $message = $this->l10n->t('Failed to provision user'); |
| 492 | + return $this->build403TemplateResponse($message, Http::STATUS_BAD_REQUEST, ['reason' => $denied->getMessage()]); |
| 493 | + } else { |
| 494 | + // error response is a redirect, e.g. to a booking site |
| 495 | + // so that you can immediately get the registration page |
| 496 | + return new RedirectResponse($redirectUrl); |
| 497 | + } |
| 498 | + } |
| 499 | + // no default exception handling to pass on unittest assertion failures |
479 | 500 | } else { |
480 | 501 | // in case user is provisioned by user_ldap, userManager->search() triggers an ldap search which syncs the results |
481 | 502 | // so new users will be directly available even if they were not synced before this login attempt |
@@ -566,7 +587,8 @@ public function singleLogoutService() { |
566 | 587 | $endSessionEndpoint .= '&client_id=' . $provider->getClientId(); |
567 | 588 | $shouldSendIdToken = $this->providerService->getSetting( |
568 | 589 | $provider->getId(), |
569 | | - ProviderService::SETTING_SEND_ID_TOKEN_HINT, '0' |
| 590 | + ProviderService::SETTING_SEND_ID_TOKEN_HINT, |
| 591 | + '0' |
570 | 592 | ) === '1'; |
571 | 593 | $idToken = $this->session->get(self::ID_TOKEN); |
572 | 594 | if ($shouldSendIdToken && $idToken) { |
@@ -715,8 +737,12 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok |
715 | 737 | * @param bool|null $throttle |
716 | 738 | * @return JSONResponse |
717 | 739 | */ |
718 | | - private function getBackchannelLogoutErrorResponse(string $error, string $description, |
719 | | - array $throttleMetadata = [], ?bool $throttle = null): JSONResponse { |
| 740 | + private function getBackchannelLogoutErrorResponse( |
| 741 | + string $error, |
| 742 | + string $description, |
| 743 | + array $throttleMetadata = [], |
| 744 | + ?bool $throttle = null |
| 745 | + ): JSONResponse { |
720 | 746 | $this->logger->debug('Backchannel logout error. ' . $error . ' ; ' . $description); |
721 | 747 | $response = new JSONResponse( |
722 | 748 | [ |
|
0 commit comments