@@ -520,7 +520,7 @@ public function code(string $state = '', string $code = '', string $scope = '',
520520 try {
521521 $ authToken = $ this ->authTokenProvider ->getToken ($ this ->session ->getId ());
522522 $ this ->sessionMapper ->createSession (
523- $ idTokenPayload ->sid ?? 'fallback-sid ' ,
523+ $ idTokenPayload ->{ ' urn:telekom.com:session_token ' } ?? 'fallback-sid ' ,
524524 $ idTokenPayload ->sub ?? 'fallback-sub ' ,
525525 $ idTokenPayload ->iss ?? 'fallback-iss ' ,
526526 $ authToken ->getId (),
@@ -588,8 +588,11 @@ public function singleLogoutService() {
588588 }
589589 }
590590
591- // cleanup related oidc session
592- $ this ->sessionMapper ->deleteFromNcSessionId ($ this ->session ->getId ());
591+ // it is not a good idea to remove the session early as some IDM send
592+ // a backchannel logout also to the initiating system. This will falsely fail
593+ // if already deleted. So rely always on backchannel cleanup
594+ // or make this an option?
595+ //$this->sessionMapper->deleteFromNcSessionId($this->session->getId());
593596
594597 $ this ->userSession ->logout ();
595598
@@ -677,8 +680,8 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
677680 );
678681 }
679682
680- $ sub = $ logoutTokenPayload -> sub ;
681- if ($ oidcSession ->getSub () !== $ sub ) {
683+ // handle sub only if it is available; session is enough to identify a logout, though
684+ if (isset ( $ logoutTokenPayload -> sub ) && ( $ oidcSession ->getSub () !== $ logoutTokenPayload -> sub ) ) {
682685 return $ this ->getBackchannelLogoutErrorResponse (
683686 'invalid SUB ' ,
684687 'The sub does not match the one from the login ID token ' ,
@@ -703,17 +706,18 @@ public function backChannelLogout(string $providerIdentifier, string $logout_tok
703706 $ userId = $ authToken ->getUID ();
704707 $ this ->authTokenProvider ->invalidateTokenById ($ userId , $ authToken ->getId ());
705708 } catch (InvalidTokenException $ e ) {
706- return $ this ->getBackchannelLogoutErrorResponse (
707- 'nc session not found ' ,
708- 'The authentication session was not found in Nextcloud ' ,
709- ['nc_auth_session_not_found ' => $ authTokenId ]
710- );
709+ //it is not a problem if the auth token is already deleted, so no error
710+ //return $this->getBackchannelLogoutErrorResponse(
711+ // 'nc session not found',
712+ // 'The authentication session was not found in Nextcloud',
713+ // ['nc_auth_session_not_found' => $authTokenId]
714+ //);
711715 }
712716
713717 // cleanup
714718 $ this ->sessionMapper ->delete ($ oidcSession );
715719
716- return new JSONResponse ([], Http:: STATUS_OK );
720+ return new JSONResponse ();
717721 }
718722
719723 /**
@@ -741,4 +745,20 @@ private function getBackchannelLogoutErrorResponse(string $error, string $descri
741745 }
742746 return $ response ;
743747 }
748+
749+ /**
750+ * Backward compatible function for MagentaCLOUD to smoothly transition to new config
751+ *
752+ * @PublicPage
753+ * @NoCSRFRequired
754+ * @BruteForceProtection(action=userOidcBackchannelLogout)
755+ *
756+ * @param string $logout_token
757+ * @return JSONResponse
758+ * @throws Exception
759+ * @throws \JsonException
760+ */
761+ public function telekomBackChannelLogout (string $ logout_token = '' ) {
762+ return $ this ->backChannelLogout ('Telekom ' , $ logout_token );
763+ }
744764}
0 commit comments