Bearers Reference
JWTClaims
missil.JWTClaims
Bases: TypedDict
Base TypedDict for JWT claim payloads (RFC 7519).
All standard JWT registered claims are declared as optional fields.
Subclass this to add application-specific claims with full type-checker
support while remaining a plain :class:dict at runtime.
| ATTRIBUTE | DESCRIPTION |
|---|---|
exp |
Expiration time — Unix timestamp after which the token is invalid. Validated automatically by PyJWT on decode.
TYPE:
|
iat |
Issued at — Unix timestamp of when the token was issued.
TYPE:
|
nbf |
Not before — Unix timestamp before which the token is not valid. Validated automatically by PyJWT on decode.
TYPE:
|
sub |
Subject — identifier of the token's subject (e.g. user ID).
TYPE:
|
iss |
Issuer — identifies who issued the token (e.g.
TYPE:
|
aud |
Audience — identifies the recipients the token is intended for.
TYPE:
|
jti |
JWT ID — unique identifier for the token, useful for revocation.
TYPE:
|
Examples:
The field holding user permissions must match the permissions_key
configured on the bearer instance:
Declare a subclass with a field of the same name:
from missil import JWTClaims
class AppClaims(JWTClaims):
username: str
scopes: dict[str, int] # must match permissions_key
Then annotate route parameters with the subclass:
TokenBearer
missil.TokenBearer
TokenBearer(token_key, secret_key, permissions_key=None, algorithms='HS256', *, user_permissions_key=None)
Bases: TokenSource
Try to read the token from cookies, falling back to the request header.
Configure JWT token extraction and decoding.
| PARAMETER | DESCRIPTION |
|---|---|
token_key
|
Name of the header or cookie key that carries the JWT token.
TYPE:
|
secret_key
|
Secret key used to decode the signed token.
TYPE:
|
permissions_key
|
Key inside the decoded JWT payload that holds the permissions dict. Example payload:
TYPE:
|
algorithms
|
JWT decoding algorithm(s), by default "HS256". See PyJWT docs for supported values.
TYPE:
|
user_permissions_key
|
Deprecated. Use
TYPE:
|
Source code in missil/bearers.py
algorithms
instance-attribute
split_token_str
get_token_from_cookies
Read the token value from http cookies.
Source code in missil/bearers.py
get_token_from_header
Get the token value from request headers.
Source code in missil/bearers.py
decode_jwt
Decode a retrieved token value and return the full JWT claims.
decode_from_cookies
decode_from_header
get_user_permissions
Get user permissions from a decoded token.
Source code in missil/bearers.py
CookieTokenBearer
missil.CookieTokenBearer
CookieTokenBearer(token_key, secret_key, permissions_key=None, algorithms='HS256', *, user_permissions_key=None)
Bases: TokenSource
Read JWT token from http cookies.
Configure JWT token extraction and decoding.
| PARAMETER | DESCRIPTION |
|---|---|
token_key
|
Name of the header or cookie key that carries the JWT token.
TYPE:
|
secret_key
|
Secret key used to decode the signed token.
TYPE:
|
permissions_key
|
Key inside the decoded JWT payload that holds the permissions dict. Example payload:
TYPE:
|
algorithms
|
JWT decoding algorithm(s), by default "HS256". See PyJWT docs for supported values.
TYPE:
|
user_permissions_key
|
Deprecated. Use
TYPE:
|
Source code in missil/bearers.py
algorithms
instance-attribute
split_token_str
get_token_from_cookies
Read the token value from http cookies.
Source code in missil/bearers.py
get_token_from_header
Get the token value from request headers.
Source code in missil/bearers.py
decode_jwt
Decode a retrieved token value and return the full JWT claims.
decode_from_cookies
decode_from_header
get_user_permissions
Get user permissions from a decoded token.
Source code in missil/bearers.py
HeaderTokenBearer
missil.HeaderTokenBearer
HeaderTokenBearer(token_key, secret_key, permissions_key=None, algorithms='HS256', *, user_permissions_key=None)
Bases: TokenSource
Read JWT token from the Authorization request header.
Configure JWT token extraction and decoding.
| PARAMETER | DESCRIPTION |
|---|---|
token_key
|
Name of the header or cookie key that carries the JWT token.
TYPE:
|
secret_key
|
Secret key used to decode the signed token.
TYPE:
|
permissions_key
|
Key inside the decoded JWT payload that holds the permissions dict. Example payload:
TYPE:
|
algorithms
|
JWT decoding algorithm(s), by default "HS256". See PyJWT docs for supported values.
TYPE:
|
user_permissions_key
|
Deprecated. Use
TYPE:
|
Source code in missil/bearers.py
algorithms
instance-attribute
split_token_str
get_token_from_cookies
Read the token value from http cookies.
Source code in missil/bearers.py
get_token_from_header
Get the token value from request headers.
Source code in missil/bearers.py
decode_jwt
Decode a retrieved token value and return the full JWT claims.
decode_from_cookies
decode_from_header
get_user_permissions
Get user permissions from a decoded token.