Skip to content

Commit 3ddcfa9

Browse files
committed
fix error
1 parent 217b647 commit 3ddcfa9

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

lib/Controller/LoginController.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,21 +487,14 @@ public function code(string $state = '', string $code = '', string $scope = '',
487487
}
488488

489489
if ($autoProvisionAllowed) {
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-
498490
// TODO: (proposal) refactor all provisioning strategies into event handlers
499491
$user = null;
500492

501493
try {
494+
// use potential user from other backend, create it in our backend if it does not exist
502495
$user = $this->provisioningService->provisionUser($userId, $providerId, $idTokenPayload, $userFromOtherBackend);
503496
} catch (ProvisioningDeniedException $denied) {
504-
// TODO MagentaCLOUD should upstream the exception handling
497+
// TODO: MagentaCLOUD should upstream the exception handling
505498
$redirectUrl = $denied->getRedirectUrl();
506499
if ($redirectUrl === null) {
507500
$message = $this->l10n->t('Failed to provision user');
@@ -513,9 +506,12 @@ public function code(string $state = '', string $code = '', string $scope = '',
513506
}
514507
}
515508

516-
// use potential user from other backend, create it in our backend if it does not exist
517-
// $user = $this->provisioningService->provisionUser($userId, $providerId, $idTokenPayload, $userFromOtherBackend);
518-
// no default exception handling to pass on unittest assertion failures
509+
if (!$softAutoProvisionAllowed && $userFromOtherBackend !== null && $user === null) {
510+
// if soft auto-provisioning is disabled,
511+
// we refuse login for a user that already exists in another backend
512+
$message = $this->l10n->t('User conflict');
513+
return $this->build403TemplateResponse($message, Http::STATUS_BAD_REQUEST, ['reason' => 'non-soft auto provision, user conflict'], false);
514+
}
519515
} else {
520516
// when auto provision is disabled, we assume the user has been created by another user backend (or manually)
521517
$user = $userFromOtherBackend;
@@ -540,6 +536,17 @@ public function code(string $state = '', string $code = '', string $scope = '',
540536
$this->eventDispatcher->dispatchTyped(new UserLoggedInEvent($user, $user->getUID(), null, false));
541537
}
542538

539+
$tokenExchangeEnabled = (isset($oidcSystemConfig['token_exchange']) && $oidcSystemConfig['token_exchange'] === true);
540+
if ($tokenExchangeEnabled) {
541+
// store all token information for potential token exchange requests
542+
$tokenData = array_merge(
543+
$data,
544+
['provider_id' => $providerId],
545+
);
546+
$this->tokenService->storeToken($tokenData);
547+
}
548+
$this->config->setUserValue($user->getUID(), Application::APP_ID, 'had_token_once', '1');
549+
543550
// Set last password confirm to the future as we don't have passwords to confirm against with SSO
544551
$this->session->set('last-password-confirm', strtotime('+4 year', time()));
545552

@@ -796,4 +803,4 @@ private function toCodeChallenge(string $data): string {
796803
$s = str_replace('/', '_', $s); // 63rd char of encoding
797804
return $s;
798805
}
799-
}
806+
}

0 commit comments

Comments
 (0)