Skip to content

API Reference parrot.auth.session_identity

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.auth.session_identity

View source

Backend-independent resolution of the authenticated user's id.

navigator-auth does not guarantee a flat user_id anywhere. What a backend puts in the session is driven by its own userid_attribute, which differs per backend — user_id (BasicAuth / Troc / Django), id (Azure), login (GitHub), upn (ADFS), object_id (SAML), userid (NoAuth) — and by the deployment-level AUTH_USERID_ATTRIBUTE setting. Reading session["user_id"] therefore only works for the BasicAuth-shaped backends; nothing at all sets request["user_id"].

The one field EVERY backend populates is Identity.id on the :class:navigator_auth.identities.AuthUser object that the auth middleware and @user_session() attach to request.user (and, for class-based views, to self.user). Identity.id is typed Any: an int primary key for DB-backed users, a string for token/external identities — so callers that key caches, memory, or permission principals by it must normalize it to str, which :func:resolve_user_id does.

Function resolve_session_user

Return the AuthUser/Identity navigator-auth attached, if any.

The auth middleware sets both request.user (attribute) and request["user"] (mapping key, SESSION_USER_PROPERTY); the @user_session() decorator sets the same object on the view. Both forms are checked because a handler may run behind either.

resolve_session_user(request: Any) -> Any | None

Parameter Type Default Description
request Any The incoming aiohttp request.

Returns: Any | None — The identity object, or None when the request is unauthenticated.

Function resolve_user_id

Resolve the authenticated user's id as a string, backend-independently.

Resolution order (first non-empty wins):

  1. request.user / request["user"] -> Identity.id (the only field every navigator-auth backend sets), then that object's native id attributes and finally its username.
  2. The session's flat AUTH_USERID_ATTRIBUTE key (user_id by default) — what BasicAuth-shaped backends write.
  3. The same key nested under AUTH_SESSION_OBJECT — navigator-auth's own fallback for external/OAuth2 backends (see backends/external.py, which does exactly this two-step lookup).

resolve_user_id(request: Any, session: Any = None) -> str | None

Parameter Type Default Description
request Any The incoming aiohttp request.
session Any None An already-resolved session (SessionData), when the caller has one. Optional — steps 2 and 3 are skipped without it.

Returns: str | None — The user id as str, or None when no identity can be resolved. Non-string ids (an int primary key, a UUID) are coerced, so the value is safe to use as a cache/memory key or a permission principal.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally