Skip to content

docs: Added docs for anonymous sessions - #122

Merged
rmad17 merged 10 commits into
mainfrom
docs/anon-sessions
Oct 1, 2026
Merged

rmad17 merged 10 commits into
mainfrom
docs/anon-sessions

Conversation

@rmad17

@rmad17 rmad17 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Added

@rmad17
rmad17 marked this pull request as ready for review September 28, 2026 05:47
@rmad17
rmad17 requested a review from a team as a code owner September 28, 2026 05:47
Comment thread README.md Outdated

### 8. Anonymous Sessions

[Anonymous Sessions](https://auth0.com/docs) give a visitor an Auth0 identity before they log in. The access token issued for an anonymous session is a standard Auth0 Bearer JWT, so `verify_access_token()` and `verify_request()` validate it exactly like any other token. The only difference is the `sub` claim, which starts with `anon@`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link just points to the docs home page, not the Anonymous Sessions page, so the learn more does not really take the reader anywhere useful. Can we point it to the actual Anonymous Sessions doc page? If the final URL is not ready yet, it may be better to drop the link for now than to ship a placeholder.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — updated the link to point to https://auth0.com/docs/manage-users/sessions/anonymous-sessions, which is the canonical Anonymous Sessions docs page.

Comment thread README.md Outdated
- **[Multi-Custom Domain Guide](docs/MultipleCustomDomain.md)** - Configuration modes, resolver patterns, migration, error handling
- **[Caching Guide](docs/Caching.md)** - Cache tuning, custom adapters (Redis, Memcached)

### 8. Anonymous Sessions

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny naming point. The heading says Anonymous Sessions, but this SDK never creates or stores a session, it only reads the token. The EXAMPLES.md heading calls it Anonymous Callers, which fits an API SDK better. Can we align the two, and maybe add one line saying that session creation lives in the web app SDK, not here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — renamed the section to Anonymous Callers to align with EXAMPLES.md and to reflect that this SDK only validates tokens. Added a sentence clarifying that anonymous session creation is handled by web app.

Comment thread EXAMPLES.md Outdated

Anonymous Sessions give a visitor an Auth0 identity before they log in. The access token issued for an anonymous session is a standard Auth0 Bearer JWT, so this SDK validates it like any other token. The one difference is the `sub` claim, which starts with `anon@`.

An anonymous token passes verification by default. To treat anonymous callers differently, or block them, check the `sub` claim after verifying the token. The SDK does not make that authorization decision for you.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small clarification here. An anonymous token passes only when it was issued for this API's audience, exactly like any other token, since verify_access_token still checks aud. Can we add half a line saying the anonymous session must be issued for this API's audience? Otherwise a reader may assume every anon@ token will verify here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — replaced "passes verification by default" with two explicit sentences: the token is verified like any other, and it must be issued for this API's audience.

Comment thread EXAMPLES.md Outdated
### Serve everyone, branch in the handler

```python
import asyncio

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small things on imports. asyncio is imported but not used in this snippet (there is no asyncio.run shown), so it can be dropped. Also the next two snippets use ApiClient and ApiClientOptions without importing them, whereas the other examples in this file repeat their imports. Can we tidy both so each block is copy paste ready?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — dropped the unused import asyncio from the first snippet, and added from auth0_api_python import ApiClient, ApiClientOptions to the second and third snippets so all three are copy-paste ready.

Comment thread EXAMPLES.md
from auth0_api_python import ApiClient, ApiClientOptions

async def handle_cart(headers):
api_client = ApiClient(ApiClientOptions(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing worth flagging for readers. Building the ApiClient inside the handler means the discovery and JWKS caches are recreated on every request, so each call refetches them. This matches the other examples in the file so it is not a blocker, but a one line note to build the client once and reuse it (or pass a shared cache_adapter) would help people who copy this into a hot path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note at the end of the section: in production, build ApiClient once at startup and reuse it, or pass a shared cache_adapter, so JWKS and discovery caches persist across requests.

Comment thread EXAMPLES.md

claims = await api_client.verify_request(headers=headers)
if claims.get("sub", "").startswith("anon@"):
raise PermissionError("Anonymous callers are not allowed on this route")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For an API this case is usually a 403. PermissionError is fine as pseudo code, but can we add a short note to map it to a 403 in the reader's framework? That makes the intent clearer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note: blocking an anonymous caller should return an HTTP 403 Forbidden — replace PermissionError with your framework's error type.

@rmad17
rmad17 merged commit 8c95b76 into main Oct 1, 2026
7 checks passed
@rmad17
rmad17 deleted the docs/anon-sessions branch October 1, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants