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 a ConfigManager 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, or None 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), otherwise False.

Return type:

bool

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: