Skip to content

xtr_security_jwt

Self-issued JSON Web Tokens for xtr security: encoder, token manager and authenticator.

JwtTokenManagerInterface

Bases: Protocol

Mints a signed token for a user, and reads a presented one back into claims.

The manager assembles the payload — the user's roles and the claim naming who they are — enriches it, announces it for a listener to shape, signs it, and announces the finished token. Reading a token back verifies it and announces its payload, which a listener may reject.

create async

create(user: UserInterface) -> str

Mint a signed token for user, carrying its roles and identity.

create_from_payload async

create_from_payload(user: UserInterface, payload: Mapping[str, object]) -> str

Mint a signed token for user, starting from a caller's payload.

decode async

decode(token: TokenInterface) -> Mapping[str, object] | bool

Read the claims out of a security token, or False when it has none.

parse async

parse(token: str) -> Mapping[str, object]

Verify a compact token and return its claims.

Raises:

  • JwtDecodeFailureError –

    When the token cannot be read, has expired, or its signature does not verify.

get_user_id_claim

get_user_id_claim() -> str

Return the claim the user's identifier is written into.