Skip to content

Commit 4fc8e73

Browse files
committed
Merge #10 Fix backchannel logout for Telekom and keep backward compatibility
2 parents 5172fd4 + b2016b9 commit 4fc8e73

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

lib/Controller/LoginController.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ public function code(string $state = '', string $code = '', string $scope = '',
530530
try {
531531
$authToken = $this->authTokenProvider->getToken($this->session->getId());
532532
$this->sessionMapper->createSession(
533-
$idTokenPayload->sid ?? 'fallback-sid',
533+
$idTokenPayload->{'urn:telekom.com:session_token'} ?? 'fallback-sid',
534534
$idTokenPayload->sub ?? 'fallback-sub',
535535
$idTokenPayload->iss ?? 'fallback-iss',
536536
$authToken->getId(),
@@ -599,8 +599,11 @@ public function singleLogoutService() {
599599
}
600600
}
601601

602-
// cleanup related oidc session
603-
$this->sessionMapper->deleteFromNcSessionId($this->session->getId());
602+
// it is not a good idea to remove the session early as some IDM send
603+
// a backchannel logout also to the initiating system. This will falsely fail
604+
// if already deleted. So rely always on backchannel cleanup
605+
// or make this an option?
606+
//$this->sessionMapper->deleteFromNcSessionId($this->session->getId());
604607

605608
$this->userSession->logout();
606609

@@ -688,8 +691,8 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
688691
);
689692
}
690693

691-
$sub = $logoutTokenPayload->sub;
692-
if ($oidcSession->getSub() !== $sub) {
694+
// handle sub only if it is available; session is enough to identify a logout, though
695+
if (isset($logoutTokenPayload->sub) && ($oidcSession->getSub() !== $logoutTokenPayload->sub)) {
693696
return $this->getBackchannelLogoutErrorResponse(
694697
'invalid SUB',
695698
'The sub does not match the one from the login ID token',
@@ -714,17 +717,18 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
714717
$userId = $authToken->getUID();
715718
$this->authTokenProvider->invalidateTokenById($userId, $authToken->getId());
716719
} catch (InvalidTokenException $e) {
717-
return $this->getBackchannelLogoutErrorResponse(
718-
'nc session not found',
719-
'The authentication session was not found in Nextcloud',
720-
['nc_auth_session_not_found' => $authTokenId]
721-
);
720+
//it is not a problem if the auth token is already deleted, so no error
721+
//return $this->getBackchannelLogoutErrorResponse(
722+
// 'nc session not found',
723+
// 'The authentication session was not found in Nextcloud',
724+
// ['nc_auth_session_not_found' => $authTokenId]
725+
//);
722726
}
723727

724728
// cleanup
725729
$this->sessionMapper->delete($oidcSession);
726730

727-
return new JSONResponse([], Http::STATUS_OK);
731+
return new JSONResponse();
728732
}
729733

730734
/**
@@ -756,4 +760,20 @@ private function getBackchannelLogoutErrorResponse(
756760
}
757761
return $response;
758762
}
763+
764+
/**
765+
* Backward compatible function for MagentaCLOUD to smoothly transition to new config
766+
*
767+
* @PublicPage
768+
* @NoCSRFRequired
769+
* @BruteForceProtection(action=userOidcBackchannelLogout)
770+
*
771+
* @param string $logout_token
772+
* @return JSONResponse
773+
* @throws Exception
774+
* @throws \JsonException
775+
*/
776+
public function telekomBackChannelLogout(string $logout_token = '') {
777+
return $this->backChannelLogout('Telekom', $logout_token);
778+
}
759779
}

0 commit comments

Comments
 (0)