Access Token#

class AccessToken(*, token: SecretStr = SecretStr(''), expires: datetime = <factory>)[source]#

Represents a Bearer Token used for authentication.

The token is held as pydantic.SecretStr so accidental repr / model_dump / str() / traceback rendering returns the masked placeholder rather than the actual bearer. Use access_token.token.get_secret_value() when constructing the Authorization header or persisting to the keychain.

Parameters:
  • token (pydantic.SecretStr) – The access token used for authentication.

  • expires (datetime) – The expiration datetime of the token. The default is set to January 1, 1970.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

property is_expired: bool[source]#

True if the token has expired (within 60 seconds of its expiration time).

property seconds_remaining: int[source]#

Seconds remaining until the token expires (0 if already expired).