@@ -768,13 +768,22 @@ async def logout(
768768 ) -> str :
769769 options = options or LogoutOptions ()
770770
771- # Delete the session from the state store
772- await self ._state_store .delete (self ._state_identifier , store_options )
771+ if not self ._domain_resolver :
772+ await self ._state_store .delete (self ._state_identifier , store_options )
773+ domain = self ._domain
774+ else :
775+ # Resolver mode: delete session if domains match
776+ domain = await self ._resolve_current_domain (store_options )
777+ state_data = await self ._state_store .get (self ._state_identifier , store_options )
773778
774- # Resolve domain dynamically for MCD support
775- domain = await self ._resolve_current_domain (store_options )
779+ if state_data :
780+ if hasattr (state_data , "dict" ) and callable (state_data .dict ):
781+ state_data = state_data .dict ()
782+ session_domain = state_data .get ("domain" )
783+ if session_domain and self ._normalize_issuer (session_domain ) == self ._normalize_issuer (domain ):
784+ await self ._state_store .delete (self ._state_identifier , store_options )
776785
777- # Use the URL helper to create the logout URL.
786+ # Return logout URL for the current resolved domain
778787 logout_url = URL .create_logout_url (
779788 domain , self ._client_id , options .return_to )
780789
@@ -828,7 +837,7 @@ async def handle_backchannel_logout(
828837 jwks = await self ._get_jwks_cached (domain )
829838
830839 try :
831- claims = await self ._verify_and_decode_jwt (logout_token , jwks )
840+ claims = await self ._verify_and_decode_jwt (logout_token , jwks , audience = self . _client_id )
832841
833842 # Normalized issuer validation
834843 token_issuer = claims .get ("iss" , "" )
@@ -861,7 +870,12 @@ async def handle_backchannel_logout(
861870 sid = claims .get ("sid" )
862871 )
863872
864- await self ._state_store .delete_by_logout_token (logout_claims .dict (), store_options )
873+ # In resolver mode, include iss for issuer-scoped deletion
874+ claims_dict = logout_claims .dict ()
875+ if self ._domain_resolver :
876+ claims_dict ["iss" ] = claims .get ("iss" )
877+
878+ await self ._state_store .delete_by_logout_token (claims_dict , store_options )
865879
866880 except (jwt .PyJWTError , ValidationError ) as e :
867881 raise BackchannelLogoutError (
@@ -1473,7 +1487,9 @@ async def start_link_user(
14731487
14741488 # In resolver mode, reject sessions without domain or with mismatched domain
14751489 if self ._domain_resolver :
1476- session_domain = state_data .get ('domain' ) if isinstance (state_data , dict ) else getattr (state_data , 'domain' , None )
1490+ if hasattr (state_data , "dict" ) and callable (state_data .dict ):
1491+ state_data = state_data .dict ()
1492+ session_domain = state_data .get ('domain' )
14771493 if not session_domain :
14781494 raise StartLinkUserError (
14791495 "Session is missing domain. User needs to re-authenticate."
@@ -1568,7 +1584,9 @@ async def start_unlink_user(
15681584
15691585 # In resolver mode, reject sessions without domain or with mismatched domain
15701586 if self ._domain_resolver :
1571- session_domain = state_data .get ('domain' ) if isinstance (state_data , dict ) else getattr (state_data , 'domain' , None )
1587+ if hasattr (state_data , "dict" ) and callable (state_data .dict ):
1588+ state_data = state_data .dict ()
1589+ session_domain = state_data .get ('domain' )
15721590 if not session_domain :
15731591 raise StartLinkUserError (
15741592 "Session is missing domain. User needs to re-authenticate."
0 commit comments