Skip to content

Commit 3d36380

Browse files
committed
Merge #10 Fix backchannel logout for Telekom and keep backward compatibility
2 parents ea01f12 + b2016b9 commit 3d36380

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
@@ -541,7 +541,7 @@ public function code(string $state = '', string $code = '', string $scope = '',
541541
try {
542542
$authToken = $this->authTokenProvider->getToken($this->session->getId());
543543
$this->sessionMapper->createSession(
544-
$idTokenPayload->sid ?? 'fallback-sid',
544+
$idTokenPayload->{'urn:telekom.com:session_token'} ?? 'fallback-sid',
545545
$idTokenPayload->sub ?? 'fallback-sub',
546546
$idTokenPayload->iss ?? 'fallback-iss',
547547
$authToken->getId(),
@@ -610,8 +610,11 @@ public function singleLogoutService() {
610610
}
611611
}
612612

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

616619
$this->userSession->logout();
617620

@@ -699,8 +702,8 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
699702
);
700703
}
701704

702-
$sub = $logoutTokenPayload->sub;
703-
if ($oidcSession->getSub() !== $sub) {
705+
// handle sub only if it is available; session is enough to identify a logout, though
706+
if (isset($logoutTokenPayload->sub) && ($oidcSession->getSub() !== $logoutTokenPayload->sub)) {
704707
return $this->getBackchannelLogoutErrorResponse(
705708
'invalid SUB',
706709
'The sub does not match the one from the login ID token',
@@ -725,17 +728,18 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
725728
$userId = $authToken->getUID();
726729
$this->authTokenProvider->invalidateTokenById($userId, $authToken->getId());
727730
} catch (InvalidTokenException $e) {
728-
return $this->getBackchannelLogoutErrorResponse(
729-
'nc session not found',
730-
'The authentication session was not found in Nextcloud',
731-
['nc_auth_session_not_found' => $authTokenId]
732-
);
731+
//it is not a problem if the auth token is already deleted, so no error
732+
//return $this->getBackchannelLogoutErrorResponse(
733+
// 'nc session not found',
734+
// 'The authentication session was not found in Nextcloud',
735+
// ['nc_auth_session_not_found' => $authTokenId]
736+
//);
733737
}
734738

735739
// cleanup
736740
$this->sessionMapper->delete($oidcSession);
737741

738-
return new JSONResponse([], Http::STATUS_OK);
742+
return new JSONResponse();
739743
}
740744

741745
/**
@@ -767,4 +771,20 @@ private function getBackchannelLogoutErrorResponse(
767771
}
768772
return $response;
769773
}
774+
775+
/**
776+
* Backward compatible function for MagentaCLOUD to smoothly transition to new config
777+
*
778+
* @PublicPage
779+
* @NoCSRFRequired
780+
* @BruteForceProtection(action=userOidcBackchannelLogout)
781+
*
782+
* @param string $logout_token
783+
* @return JSONResponse
784+
* @throws Exception
785+
* @throws \JsonException
786+
*/
787+
public function telekomBackChannelLogout(string $logout_token = '') {
788+
return $this->backChannelLogout('Telekom', $logout_token);
789+
}
770790
}

0 commit comments

Comments
 (0)