Token Manager¶
- class TokenManager(config: ConfigManager)[source]¶
The
TokenManagerclass handles all operations related to the token lifecycle, including fetching, saving, and validating the access token.It is initialized with a
ConfigManagerinstance, which provides the necessary credentials.- Parameters:
config (
ConfigManager) – AConfigManagerinstance for managing credentials and configurations.
- load_token() AccessToken[source]¶
Loads the
AccessTokenand its expiration from the keyring.If either the AccessToken string or AccessToken expiration cannot be retrieved, a
CredentialErroris raised.- Returns:
An AccessToken object containing the token and its expiration date.
- Return type:
- attach_client() JamfCredentials[source]¶
Creates and returns a
JamfCredentialsobject using the stored credentials.- Returns:
The
JamfCredentialsobject if validation is successful.- Return type:
- Raises:
PatcherError – If
JamfCredentialsobject fails pydantic validation.
- async fetch_token() AccessToken[source]¶
Asynchronously fetches a new access token from the Jamf API. The token is then saved and returned for use.
- Returns:
The fetched
AccessTokeninstance.- Return type:
- Raises:
TokenError – If a token cannot be retrieved from the Jamf API.
- save_token(token: AccessToken)[source]¶
This method stores the access token and its expiration date in the keyring for later retrieval.
- Parameters:
token (
AccessToken) – TheAccessTokeninstance containing the token and its expiration date.- Raises:
TokenError – If either the token string or expiration could not be saved.
- async ensure_valid_token() AccessToken[source]¶
Verify the current access token is valid (present and not expired); refresh it if not. Pydantic
ValidationErrorfrom the underlying token or client objects is translated toTokenErrorso callers see a single, consistent exception type for token-validation failures.Called by
_headers()on every Jamf request. Every API method onJamfClientbuilds its headers via that method, so token validation runs exactly once per request without a separate decorator.- Returns:
The
AccessTokenobject by way ofself.tokenproperty.- Return type:
- Raises:
TokenError – If the access token or jamf client fail pydantic validation, or if a refresh attempt fails.