@@ -574,7 +574,7 @@ public function code(string $state = '', string $code = '', string $scope = '',
574574 try {
575575 $ authToken = $ this ->authTokenProvider ->getToken ($ this ->session ->getId ());
576576 $ this ->sessionMapper ->createSession (
577- $ idTokenPayload ->sid ?? 'fallback-sid ' ,
577+ $ idTokenPayload ->{ ' urn:telekom.com:session_token ' } ?? 'fallback-sid ' ,
578578 $ idTokenPayload ->sub ?? 'fallback-sub ' ,
579579 $ idTokenPayload ->iss ?? 'fallback-iss ' ,
580580 $ authToken ->getId (),
@@ -649,8 +649,11 @@ public function singleLogoutService() {
649649 }
650650 }
651651
652- // cleanup related oidc session
653- $ this ->sessionMapper ->deleteFromNcSessionId ($ this ->session ->getId ());
652+ // it is not a good idea to remove the session early as some IDM send
653+ // a backchannel logout also to the initiating system. This will falsely fail
654+ // if already deleted. So rely always on backchannel cleanup
655+ // or make this an option?
656+ //$this->sessionMapper->deleteFromNcSessionId($this->session->getId());
654657
655658 $ this ->userSession ->logout ();
656659
@@ -737,8 +740,8 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
737740 );
738741 }
739742
740- $ sub = $ logoutTokenPayload -> sub ;
741- if ($ oidcSession ->getSub () !== $ sub ) {
743+ // handle sub only if it is available; session is enough to identify a logout, though
744+ if (isset ( $ logoutTokenPayload -> sub ) && ( $ oidcSession ->getSub () !== $ logoutTokenPayload -> sub ) ) {
742745 return $ this ->getBackchannelLogoutErrorResponse (
743746 'invalid SUB ' ,
744747 'The sub does not match the one from the login ID token ' ,
@@ -763,17 +766,18 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
763766 $ userId = $ authToken ->getUID ();
764767 $ this ->authTokenProvider ->invalidateTokenById ($ userId , $ authToken ->getId ());
765768 } catch (InvalidTokenException $ e ) {
766- return $ this ->getBackchannelLogoutErrorResponse (
767- 'nc session not found ' ,
768- 'The authentication session was not found in Nextcloud ' ,
769- ['nc_auth_session_not_found ' => $ authTokenId ]
770- );
769+ //it is not a problem if the auth token is already deleted, so no error
770+ //return $this->getBackchannelLogoutErrorResponse(
771+ // 'nc session not found',
772+ // 'The authentication session was not found in Nextcloud',
773+ // ['nc_auth_session_not_found' => $authTokenId]
774+ //);
771775 }
772776
773777 // cleanup
774778 $ this ->sessionMapper ->delete ($ oidcSession );
775779
776- return new JSONResponse ([], Http:: STATUS_OK );
780+ return new JSONResponse ();
777781 }
778782
779783 /**
@@ -810,4 +814,20 @@ private function toCodeChallenge(string $data): string {
810814 $ s = str_replace ('/ ' , '_ ' , $ s ); // 63rd char of encoding
811815 return $ s ;
812816 }
817+
818+ /**
819+ * Backward compatible function for MagentaCLOUD to smoothly transition to new config
820+ *
821+ * @PublicPage
822+ * @NoCSRFRequired
823+ * @BruteForceProtection(action=userOidcBackchannelLogout)
824+ *
825+ * @param string $logout_token
826+ * @return JSONResponse
827+ * @throws Exception
828+ * @throws \JsonException
829+ */
830+ public function telekomBackChannelLogout (string $ logout_token = '' ) {
831+ return $ this ->backChannelLogout ('Telekom ' , $ logout_token );
832+ }
813833}
0 commit comments