JWT¶
Reference for the built-in JWT authenticator and its token classes. See the JWT guide for an overview, configuration, worked examples, and the full settings reference.
JWTAuthentication ¶
Bases: BaseAuthentication
Bearer token authentication using JSON Web Tokens. Validates signature, expiry, issuer, and audience via PyJWT, and looks up the user via async ORM.
authenticate ¶
Returns a (user, token) tuple for the bearer token in the Authorization header, or None when no token is supplied.
aauthenticate
async
¶
Returns a (user, token) tuple for the bearer token in the Authorization header, or None when no token is supplied.
authenticate_header ¶
Returns the WWW-Authenticate header value used on 401 responses.
AccessToken
dataclass
¶
Bases: _Token
Short-lived bearer token sent on every authenticated request.
RefreshToken
dataclass
¶
Bases: _Token
Long-lived token used to mint new access tokens without forcing the user to log in again.
access_token
property
¶
Returns a fresh access token derived from this refresh token's user claim.
for_user
classmethod
¶
Returns a freshly signed refresh token for the given user.
verify
classmethod
¶
Decodes and validates the raw refresh token, raising TokenError on any failure.
rotate ¶
Returns a fresh refresh token derived from this token's user claim.
TokenError ¶
Bases: Exception
Raised when a JWT cannot be decoded, has expired, or fails verification.