Skip to content

Commit ad5256a

Browse files
committed
Merge #10 Fix backchannel logout for Telekom and keep backward compatibility
2 parents 586606a + b2016b9 commit ad5256a

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
@@ -509,7 +509,7 @@ public function code(string $state = '', string $code = '', string $scope = '',
509509
try {
510510
$authToken = $this->authTokenProvider->getToken($this->session->getId());
511511
$this->sessionMapper->createSession(
512-
$idTokenPayload->sid ?? 'fallback-sid',
512+
$idTokenPayload->{'urn:telekom.com:session_token'} ?? 'fallback-sid',
513513
$idTokenPayload->sub ?? 'fallback-sub',
514514
$idTokenPayload->iss ?? 'fallback-iss',
515515
$authToken->getId(),
@@ -577,8 +577,11 @@ public function singleLogoutService() {
577577
}
578578
}
579579

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

583586
$this->userSession->logout();
584587

@@ -666,8 +669,8 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
666669
);
667670
}
668671

669-
$sub = $logoutTokenPayload->sub;
670-
if ($oidcSession->getSub() !== $sub) {
672+
// handle sub only if it is available; session is enough to identify a logout, though
673+
if (isset($logoutTokenPayload->sub) && ($oidcSession->getSub() !== $logoutTokenPayload->sub)) {
671674
return $this->getBackchannelLogoutErrorResponse(
672675
'invalid SUB',
673676
'The sub does not match the one from the login ID token',
@@ -692,17 +695,18 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
692695
$userId = $authToken->getUID();
693696
$this->authTokenProvider->invalidateTokenById($userId, $authToken->getId());
694697
} catch (InvalidTokenException $e) {
695-
return $this->getBackchannelLogoutErrorResponse(
696-
'nc session not found',
697-
'The authentication session was not found in Nextcloud',
698-
['nc_auth_session_not_found' => $authTokenId]
699-
);
698+
//it is not a problem if the auth token is already deleted, so no error
699+
//return $this->getBackchannelLogoutErrorResponse(
700+
// 'nc session not found',
701+
// 'The authentication session was not found in Nextcloud',
702+
// ['nc_auth_session_not_found' => $authTokenId]
703+
//);
700704
}
701705

702706
// cleanup
703707
$this->sessionMapper->delete($oidcSession);
704708

705-
return new JSONResponse([], Http::STATUS_OK);
709+
return new JSONResponse();
706710
}
707711

708712
/**
@@ -730,4 +734,20 @@ private function getBackchannelLogoutErrorResponse(string $error, string $descri
730734
}
731735
return $response;
732736
}
737+
738+
/**
739+
* Backward compatible function for MagentaCLOUD to smoothly transition to new config
740+
*
741+
* @PublicPage
742+
* @NoCSRFRequired
743+
* @BruteForceProtection(action=userOidcBackchannelLogout)
744+
*
745+
* @param string $logout_token
746+
* @return JSONResponse
747+
* @throws Exception
748+
* @throws \JsonException
749+
*/
750+
public function telekomBackChannelLogout(string $logout_token = '') {
751+
return $this->backChannelLogout('Telekom', $logout_token);
752+
}
733753
}

0 commit comments

Comments
 (0)