acmadauth.tokenset module
Module defining data structures for handling JWT token sets.
- class acmadauth.tokenset.JWTToken(token, expires_in, time_obtained=<factory>)
Bases:
objectClass representing a JWT token with expiration handling.
- Parameters:
token (
str) – The JWT token string.expires_in (
int|None) – The number of seconds until the token expires, if provided.time_obtained (
float) – The timestamp when the token was obtained (default is current time).
- expires_in: int | None
- get_claims()
Decode the JWT token without verifying the signature to extract claims.
- Returns:
The claims contained in the JWT token.
- Return type:
Dict[str, Any]
- is_expired(margin=15)
Check if the token is expired, considering an optional margin. Expiration is determined by the earliest of the ‘exp’ claim in the token and the ‘expires_in’ value (if provided).
- Parameters:
margin (
int) – The number of seconds before actual expiration to consider the token as expired.- Return type:
bool- Returns:
True if the token is expired or will expire within the margin, False otherwise.
- Raises:
ValueError – If the token is not set.
- time_obtained: float
- token: str
- class acmadauth.tokenset.TokenSet(access_token, refresh_token, token_type, scope=None)
Bases:
objectClass representing a set of tokens including access and refresh tokens.
- Parameters:
- static from_json(data)
Deserialize a TokenSet from a JSON-compatible dictionary.
- Parameters:
data (
Dict[str,Any]) – The dictionary containing the token set data.- Return type:
- Returns:
The deserialized TokenSet object.
- Raises:
marshmallow.ValidationError – If the data is invalid.
- static from_token_response(data)
Create a TokenSet from a token response dictionary.
- Parameters:
data (
Dict[str,Any]) – The dictionary containing the token response data.- Return type:
- Returns:
The created TokenSet object.
- Raises:
KeyError – If required fields are missing in the data.
- scope: str | None = None
- to_json()
Serialize the TokenSet to a JSON-compatible dictionary.
- Return type:
Dict[str,Any]- Returns:
The serialized TokenSet.
- token_type: str