|
23 | 23 | use OCA\UserOIDC\Service\DiscoveryService; |
24 | 24 | use OCA\UserOIDC\Service\LdapService; |
25 | 25 | use OCA\UserOIDC\Service\ProviderService; |
| 26 | +use OCA\UserOIDC\Service\ProvisioningDeniedException; |
26 | 27 | use OCA\UserOIDC\Service\ProvisioningService; |
27 | 28 | use OCA\UserOIDC\Service\TokenService; |
28 | 29 | use OCA\UserOIDC\Vendor\Firebase\JWT\JWT; |
@@ -477,15 +478,35 @@ public function code(string $state = '', string $code = '', string $scope = '', |
477 | 478 | } |
478 | 479 |
|
479 | 480 | if ($autoProvisionAllowed) { |
480 | | - $softAutoProvisionAllowed = (!isset($oidcSystemConfig['soft_auto_provision']) || $oidcSystemConfig['soft_auto_provision']); |
481 | | - if (!$softAutoProvisionAllowed && $userFromOtherBackend !== null) { |
482 | | - // if soft auto-provisioning is disabled, |
483 | | - // we refuse login for a user that already exists in another backend |
484 | | - $message = $this->l10n->t('User conflict'); |
485 | | - return $this->build403TemplateResponse($message, Http::STATUS_BAD_REQUEST, ['reason' => 'non-soft auto provision, user conflict'], false); |
| 481 | + // $softAutoProvisionAllowed = (!isset($oidcSystemConfig['soft_auto_provision']) || $oidcSystemConfig['soft_auto_provision']); |
| 482 | + // if (!$softAutoProvisionAllowed && $userFromOtherBackend !== null) { |
| 483 | + // if soft auto-provisioning is disabled, |
| 484 | + // we refuse login for a user that already exists in another backend |
| 485 | + // $message = $this->l10n->t('User conflict'); |
| 486 | + // return $this->build403TemplateResponse($message, Http::STATUS_BAD_REQUEST, ['reason' => 'non-soft auto provision, user conflict'], false); |
| 487 | + // } |
| 488 | + |
| 489 | + // TODO: (proposal) refactor all provisioning strategies into event handlers |
| 490 | + $user = null; |
| 491 | + |
| 492 | + try { |
| 493 | + $user = $this->provisioningService->provisionUser($userId, $providerId, $idTokenPayload, $userFromOtherBackend); |
| 494 | + } catch (ProvisioningDeniedException $denied) { |
| 495 | + // TODO MagentaCLOUD should upstream the exception handling |
| 496 | + $redirectUrl = $denied->getRedirectUrl(); |
| 497 | + if ($redirectUrl === null) { |
| 498 | + $message = $this->l10n->t('Failed to provision user'); |
| 499 | + return $this->build403TemplateResponse($message, Http::STATUS_BAD_REQUEST, ['reason' => $denied->getMessage()]); |
| 500 | + } else { |
| 501 | + // error response is a redirect, e.g. to a booking site |
| 502 | + // so that you can immediately get the registration page |
| 503 | + return new RedirectResponse($redirectUrl); |
| 504 | + } |
486 | 505 | } |
| 506 | + |
487 | 507 | // use potential user from other backend, create it in our backend if it does not exist |
488 | | - $user = $this->provisioningService->provisionUser($userId, $providerId, $idTokenPayload, $userFromOtherBackend); |
| 508 | + // $user = $this->provisioningService->provisionUser($userId, $providerId, $idTokenPayload, $userFromOtherBackend); |
| 509 | + // no default exception handling to pass on unittest assertion failures |
489 | 510 | } else { |
490 | 511 | // when auto provision is disabled, we assume the user has been created by another user backend (or manually) |
491 | 512 | $user = $userFromOtherBackend; |
@@ -733,7 +754,7 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok |
733 | 754 | * @return JSONResponse |
734 | 755 | */ |
735 | 756 | private function getBackchannelLogoutErrorResponse( |
736 | | - string $error, string $description, array $throttleMetadata = [], |
| 757 | + string $error, string $description, array $throttleMetadata = [], ?bool $throttle = null, |
737 | 758 | ): JSONResponse { |
738 | 759 | $this->logger->debug('Backchannel logout error. ' . $error . ' ; ' . $description); |
739 | 760 | return new JSONResponse( |
|
0 commit comments