Skip to content

Commit 8a669df

Browse files
committed
Merge #29 [V33] Backchannel logout fix
2 parents 96636f6 + e6b556f commit 8a669df

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

lib/Controller/LoginController.php

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,26 @@ public function login(int $providerId, ?string $redirectUrl = null) {
171171
return $this->buildErrorTemplateResponse($message, Http::STATUS_NOT_FOUND, ['reason' => 'provider unreachable']);
172172
}
173173

174-
$state = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
175-
$this->session->set(self::STATE, $state);
176-
$this->session->set(self::REDIRECT_AFTER_LOGIN, $redirectUrl);
174+
// $state = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
175+
// $this->session->set(self::STATE, $state);
176+
// $this->session->set(self::REDIRECT_AFTER_LOGIN, $redirectUrl);
177177

178-
$nonce = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
179-
$this->session->set(self::NONCE, $nonce);
178+
// $nonce = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
179+
// $this->session->set(self::NONCE, $nonce);
180+
181+
// check if oidc state is present in session data
182+
if ($this->session->exists(self::STATE)) {
183+
$state = $this->session->get(self::STATE);
184+
$nonce = $this->session->get(self::NONCE);
185+
} else {
186+
$state = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
187+
$this->session->set(self::STATE, $state);
188+
$this->session->set(self::REDIRECT_AFTER_LOGIN, $redirectUrl);
189+
190+
$nonce = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
191+
$this->session->set(self::NONCE, $nonce);
192+
$this->session->set(self::PROVIDERID, $providerId);
193+
}
180194

181195
$oidcSystemConfig = $this->config->getSystemValue('user_oidc', []);
182196
$isPkceSupported = in_array('S256', $discovery['code_challenge_methods_supported'] ?? [], true);
@@ -188,7 +202,7 @@ public function login(int $providerId, ?string $redirectUrl = null) {
188202
$this->session->set(self::CODE_VERIFIER, $code_verifier);
189203
}
190204

191-
$this->session->set(self::PROVIDERID, $providerId);
205+
// $this->session->set(self::PROVIDERID, $providerId);
192206
$this->session->close();
193207

194208
// get attribute mapping settings
@@ -601,16 +615,9 @@ public function code(string $state = '', string $code = '', string $scope = '',
601615
$this->eventDispatcher->dispatchTyped(new UserLoggedInEvent($user, $user->getUID(), null, false));
602616
}
603617

604-
$storeLoginTokenEnabled = $this->appConfig->getValueString(Application::APP_ID, 'store_login_token', '0', lazy: true) === '1';
605-
if ($storeLoginTokenEnabled) {
606-
// store all token information for potential token exchange requests
607-
$tokenData = array_merge(
608-
$data,
609-
['provider_id' => $providerId],
610-
);
611-
$this->tokenService->storeToken($tokenData);
612-
}
613-
$this->config->setUserValue($user->getUID(), Application::APP_ID, 'had_token_once', '1');
618+
// remove code login session values
619+
$this->session->remove(self::STATE);
620+
$this->session->remove(self::NONCE);
614621

615622
// Set last password confirm to the future as we don't have passwords to confirm against with SSO
616623
$this->session->set('last-password-confirm', strtotime('+4 year', time()));
@@ -619,7 +626,7 @@ public function code(string $state = '', string $code = '', string $scope = '',
619626
try {
620627
$authToken = $this->authTokenProvider->getToken($this->session->getId());
621628
$this->sessionMapper->createOrUpdateSession(
622-
$idTokenPayload->sid ?? 'fallback-sid',
629+
$idTokenPayload->{'urn:telekom.com:session_token'} ?? 'fallback-sid',
623630
$idTokenPayload->sub ?? 'fallback-sub',
624631
$idTokenPayload->iss ?? 'fallback-iss',
625632
$authToken->getId(),
@@ -901,6 +908,22 @@ private function getBackchannelLogoutErrorResponse(
901908
);
902909
}
903910

911+
/**
912+
* Backward compatible function for MagentaCLOUD to smoothly transition to new config
913+
*
914+
* @PublicPage
915+
* @NoCSRFRequired
916+
* @BruteForceProtection(action=userOidcBackchannelLogout)
917+
*
918+
* @param string $logout_token
919+
* @return JSONResponse
920+
* @throws Exception
921+
* @throws \JsonException
922+
*/
923+
public function telekomBackChannelLogout(string $logout_token = '') {
924+
return $this->backChannelLogout('Telekom', $logout_token);
925+
}
926+
904927
private function toCodeChallenge(string $data): string {
905928
// Basically one big work around for the base64url decode being weird
906929
$h = pack('H*', hash('sha256', $data));

0 commit comments

Comments
 (0)