@@ -199,7 +199,6 @@ def _map_anonymous_error(
199199
200200 if code in ("session_expired" , "invalid_session_token" ):
201201 return _AnonymousSessionExpired (description )
202- # Distinguishes DPoP-mandated clients from a plain client-not-enabled block.
203202 if status_code == 400 and "Proof-of-Possession" in description :
204203 return AnonymousClientNotSupportedError (description , error_data )
205204 if code == "feature_not_enabled" :
@@ -273,10 +272,6 @@ def _encrypt_context(self, context: AnonymousSessionContext) -> str:
273272 def _decrypt_context (self , stored : Any ) -> AnonymousSessionContext :
274273 """Decrypt and validate a stored anonymous session record.
275274
276- A crypto-library failure and a validation failure both mean the
277- record is unusable, and both must convert to the same internal
278- signal instead of an untyped exception reaching the caller.
279-
280275 Args:
281276 stored: The raw record read from the anonymous store.
282277
@@ -313,8 +308,6 @@ async def _create_session_at(
313308 ) -> AnonymousSession :
314309 """Create a fresh anonymous session against a resolved domain.
315310
316- Shared by create_session() and every renewal-ladder fallback.
317-
318311 Args:
319312 domain: The resolved tenant domain.
320313 audience: Audience for the new session, or None.
@@ -344,9 +337,7 @@ async def _create_session_at(
344337 try :
345338 response = await client .post (f"{ base_url } /anonymous/token" , json = body )
346339 except httpx .HTTPError as e :
347- raise AnonymousCreateError (
348- "Failed to reach the anonymous token endpoint"
349- ) from e
340+ raise AnonymousCreateError ("Failed to reach the anonymous token endpoint" ) from e
350341
351342 if response .status_code != 200 :
352343 error_data = self ._parse_anonymous_error_body (response )
@@ -359,9 +350,7 @@ async def _create_session_at(
359350 try :
360351 token_response = AnonymousTokenResponse .model_validate (response .json ())
361352 except (json .JSONDecodeError , ValueError , ValidationError ) as e :
362- raise AnonymousCreateError (
363- "Failed to parse anonymous token response"
364- ) from e
353+ raise AnonymousCreateError ("Failed to parse anonymous token response" ) from e
365354
366355 if not token_response .session_token :
367356 raise AnonymousCreateError ("Anonymous token response missing required fields" )
@@ -408,9 +397,6 @@ async def _remint(
408397 ) -> AnonymousSession :
409398 """Re-mint an access token using the stored session token.
410399
411- Retries once by minting a brand-new session if the stored session
412- token is itself rejected as expired or invalid.
413-
414400 Args:
415401 context: The current decrypted session context.
416402 store_options: Options passed to the anonymous store.
@@ -425,7 +411,10 @@ async def _remint(
425411 """
426412 domain = context .domain or await self ._resolve_domain (store_options )
427413 base_url = f"https://{ domain } "
428- body : dict [str , Any ] = {"client_id" : self ._client_id , "session_token" : context .session_token }
414+ body : dict [str , Any ] = {
415+ "client_id" : self ._client_id ,
416+ "session_token" : context .session_token ,
417+ }
429418 if self ._client_secret :
430419 body ["client_secret" ] = self ._client_secret
431420
@@ -456,7 +445,6 @@ async def _remint(
456445
457446 now = int (time .time ())
458447 new_context = AnonymousSessionContext (
459- # Rewrite when a fresh session_token is present, else keep the old one.
460448 session_token = token_response .session_token or context .session_token ,
461449 sub = token_response .sub or context .sub ,
462450 session_id = token_response .session_id or context .session_id ,
@@ -495,18 +483,14 @@ async def _remint(
495483 async def get_session_token_for_injection (
496484 self , store_options : Optional [dict [str , Any ]] = None
497485 ) -> Optional [str ]:
498- """Read the active session token for login injection.
499-
500- Does not trigger the renewal ladder. Never raises: no configured
501- store, no active session, and an undecryptable record all return
502- None, so malformed linking state denies the link instead of
503- aborting the login.
486+ """Read the active session token for login injection without renewing.
504487
505488 Args:
506489 store_options: Options passed to the anonymous store.
507490
508491 Returns:
509- The raw session token, or None.
492+ The raw session token, or None when there is no store, no active
493+ session, or the stored record cannot be decrypted.
510494 """
511495 if self ._anonymous_store is None :
512496 return None
@@ -577,16 +561,9 @@ async def create_session(
577561 domain , audience = audience , scope = scope , metadata = metadata , store_options = store_options
578562 )
579563
580- async def get_token (
581- self , store_options : Optional [dict [str , Any ]] = None
582- ) -> AnonymousSession :
564+ async def get_token (self , store_options : Optional [dict [str , Any ]] = None ) -> AnonymousSession :
583565 """Return a valid anonymous access token, renewing or re-minting as needed.
584566
585- The renewal ladder: a fresh cached token is returned as-is. An
586- expired one is re-minted from the stored session token. A session
587- token that is itself expired or invalid silently mints a brand-new
588- session, once. Any other error is raised, never swallowed or retried.
589-
590567 Args:
591568 store_options: Options passed to the anonymous store.
592569
@@ -606,7 +583,6 @@ async def get_token(
606583 try :
607584 context = self ._decrypt_context (stored )
608585 except _AnonymousSessionExpired :
609- # No audience/scope to recover, fall back to configured defaults.
610586 domain = await self ._resolve_domain (store_options )
611587 return await self ._create_session_at (
612588 domain ,
@@ -648,11 +624,7 @@ async def get_token(
648624 async def introspect (
649625 self , store_options : Optional [dict [str , Any ]] = None
650626 ) -> AnonymousSessionIntrospection :
651- """Return the current anonymous session status without mutating it.
652-
653- Never triggers the renewal ladder and never writes to the store. An
654- unreadable stored context is a hard failure here, not a silent
655- re-mint. Uses the cached access token as a Bearer credential.
627+ """Return the current anonymous session status without mutating the store.
656628
657629 Args:
658630 store_options: Options passed to the anonymous store.
@@ -706,12 +678,7 @@ async def introspect(
706678 ) from e
707679
708680 async def logout (self , store_options : Optional [dict [str , Any ]] = None ) -> None :
709- """Clear the locally-held anonymous session.
710-
711- No server-side revocation exists: access tokens already issued
712- remain valid until natural expiry. The remote POST is best-effort
713- only. The local store clear is what actually ends the session from
714- this SDK's perspective.
681+ """Clear the locally-held anonymous session without revoking issued tokens.
715682
716683 Args:
717684 store_options: Options passed to the anonymous store.
0 commit comments