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]ΒΆ

This property evaluates whether the access token has expired. A token is considered expired if the current time is within 60 seconds of the expiration time.

Returns:

True if the token is expired.

Return type:

bool

property seconds_remaining: int[source]ΒΆ

This property calculates the time remaining before the token expires. If the token is already expired, it returns 0.

Returns:

The number of seconds remaining until the token expires.

Return type:

int