feat: add support for anonymous sessions - #156
Open
rmad17 wants to merge 7 commits into
Open
Conversation
| try: | ||
| async with self._get_http_client() as client: | ||
| await client.post(f"{base_url}/anonymous/logout", json=body) | ||
| except httpx.HTTPError: |
rmad17
marked this pull request as ready for review
August 14, 2026 06:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Added
ServerClient.anonymousfor pre-login anonymous sessions:create_session,get_token,introspect, andlogout. Gives a visitor a persistentanon@<uuid>identity plus a short-lived access token before they authenticate, with up to 1 KB of metadata attached at
creation. Framework-agnostic RWA core — mounts no routes and sets no cookies.
identifier, isolated from the authenticated
_a0_sessionstore.AnonymousSessionneverexposes the raw session token to the caller.
get_token: fresh cached access token is returned;expired access token is re-minted with the session token; an expired or invalid session
token silently creates a brand-new session, once, surfaced via
AnonymousSession.is_new. Metadata is lost andsubchanges on that silent re-mint — thisnever raises, since an anonymous pre-login session carries no authorization.
session_tokenintostart_interactive_login()automatically whena session is active, sourced only from the SDK's own encrypted store and bound into
TransactionDataunder the existingstatebinding.AnonymousSession,AnonymousTokenResponse,AnonymousSessionContext,AnonymousSessionIntrospection) and atyped error hierarchy under
AnonymousApiError, including five config subclasses(
AnonymousFeatureNotEnabledError,AnonymousClientNotEnabledError,AnonymousClientNotSupportedError,AnonymousResourceServerError,AnonymousScopeError)(
__proto__,constructor,prototype) and enforces a 1 KB (UTF-8 JSON) size cap.Testing
As part of manual testing following flows have been completed:
Happy Path
POST /anonymous/sessionmints ananon@<uuid>identity; returnssession_token(opaque JWE,ANONYMOUS_SESSION_prefix) +access_token(RS256 JWS, audience-bound).GET /anonymous/sessionwalks the renewal ladder: cached → re-mint viasession_token→ silent new session.GET /anonymous/login-urlconfirmssession_tokenis auto-injected into/authorize(session_token_injected: true), no call-site change.POST /anonymous/logoutbest-effort calls/anonymous/logout, then always clears local store; post-logoutGETreturnsAnonymousTokenError(fail-closed). Issued access tokens self-expire (notrevoked).
Negative / Fail-Closed
anonymous_resource_server_erroranonymous_scope_errorinvalid_metadata(local, pre-network)__proto__invalid_metadatametadata_too_largeAnonymousTokenErrorChecklist