@@ -542,7 +542,7 @@ public function code(string $state = '', string $code = '', string $scope = '',
542542 try {
543543 $ authToken = $ this ->authTokenProvider ->getToken ($ this ->session ->getId ());
544544 $ this ->sessionMapper ->createSession (
545- $ idTokenPayload ->sid ?? 'fallback-sid ' ,
545+ $ idTokenPayload ->{ ' urn:telekom.com:session_token ' } ?? 'fallback-sid ' ,
546546 $ idTokenPayload ->sub ?? 'fallback-sub ' ,
547547 $ idTokenPayload ->iss ?? 'fallback-iss ' ,
548548 $ authToken ->getId (),
@@ -611,8 +611,11 @@ public function singleLogoutService() {
611611 }
612612 }
613613
614- // cleanup related oidc session
615- $ this ->sessionMapper ->deleteFromNcSessionId ($ this ->session ->getId ());
614+ // it is not a good idea to remove the session early as some IDM send
615+ // a backchannel logout also to the initiating system. This will falsely fail
616+ // if already deleted. So rely always on backchannel cleanup
617+ // or make this an option?
618+ //$this->sessionMapper->deleteFromNcSessionId($this->session->getId());
616619
617620 $ this ->userSession ->logout ();
618621
@@ -700,8 +703,8 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
700703 );
701704 }
702705
703- $ sub = $ logoutTokenPayload -> sub ;
704- if ($ oidcSession ->getSub () !== $ sub ) {
706+ // handle sub only if it is available; session is enough to identify a logout, though
707+ if (isset ( $ logoutTokenPayload -> sub ) && ( $ oidcSession ->getSub () !== $ logoutTokenPayload -> sub ) ) {
705708 return $ this ->getBackchannelLogoutErrorResponse (
706709 'invalid SUB ' ,
707710 'The sub does not match the one from the login ID token ' ,
@@ -726,17 +729,18 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
726729 $ userId = $ authToken ->getUID ();
727730 $ this ->authTokenProvider ->invalidateTokenById ($ userId , $ authToken ->getId ());
728731 } catch (InvalidTokenException $ e ) {
729- return $ this ->getBackchannelLogoutErrorResponse (
730- 'nc session not found ' ,
731- 'The authentication session was not found in Nextcloud ' ,
732- ['nc_auth_session_not_found ' => $ authTokenId ]
733- );
732+ //it is not a problem if the auth token is already deleted, so no error
733+ //return $this->getBackchannelLogoutErrorResponse(
734+ // 'nc session not found',
735+ // 'The authentication session was not found in Nextcloud',
736+ // ['nc_auth_session_not_found' => $authTokenId]
737+ //);
734738 }
735739
736740 // cleanup
737741 $ this ->sessionMapper ->delete ($ oidcSession );
738742
739- return new JSONResponse ([], Http:: STATUS_OK );
743+ return new JSONResponse ();
740744 }
741745
742746 /**
@@ -768,4 +772,20 @@ private function getBackchannelLogoutErrorResponse(
768772 }
769773 return $ response ;
770774 }
775+
776+ /**
777+ * Backward compatible function for MagentaCLOUD to smoothly transition to new config
778+ *
779+ * @PublicPage
780+ * @NoCSRFRequired
781+ * @BruteForceProtection(action=userOidcBackchannelLogout)
782+ *
783+ * @param string $logout_token
784+ * @return JSONResponse
785+ * @throws Exception
786+ * @throws \JsonException
787+ */
788+ public function telekomBackChannelLogout (string $ logout_token = '' ) {
789+ return $ this ->backChannelLogout ('Telekom ' , $ logout_token );
790+ }
771791}
0 commit comments