Token Manager#
Summary
The TokenManager
handles the management of access tokens, ensuring API authorization is successful.
- class TokenManager(config: ConfigManager)[source]#
Manages the Bearer Token required for accessing the Jamf API.
The
TokenManager
class handles all operations related to the token lifecycle, including fetching, saving, and validating the access token. It is initialized with aConfigManager
instance, which provides the necessary credentials.Initializes the TokenManager with a provided
ConfigManager
instance.- Parameters:
config (ConfigManager) – A
ConfigManager
instance for managing credentials and configurations.- Raises:
ValueError – If the
JamfClient
configuration is invalid.
- async fetch_token() AccessToken | None [source]#
Asynchronously fetches a new access token from the Jamf API.
This method sends a request to the Jamf API to obtain a new token. The token is then saved and returned for use.
- Returns:
The fetched
AccessToken
instance, orNone
if the request fails.- Return type:
Optional[AccessToken]
- token_valid() bool [source]#
Determines if the current access token is still valid.
This method checks if the token has expired by evaluating its expiration date.
- Returns:
True
if the token is valid (not expired), otherwiseFalse
.- Return type:
- async ensure_valid_token()[source]#
Verifies the current access token is valid (present and not expired). If the token is found to be invalid, a new token is requested and refreshed.
- Raises:
TokenFetchError – If a new token was unable to be retrieved
TokenLifetimeError – If the token’s remaining lifetime is insufficient.