Reads the MSAL token cache file (msal_token_cache.json) from the Azure
configuration directory and returns a matching access token as an
httr2::oauth_token() object.
az_cli_get_cached_token(
scope = NULL,
tenant_id = NULL,
client_id = NULL,
config_dir = default_azure_config_dir()
)An httr2::oauth_token() object containing:
access_token: The OAuth2 access token string
token_type: The type of token (typically "Bearer")
.expires_at: POSIXct timestamp when the token expires
A character string specifying the OAuth2 scope to filter tokens.
If NULL (default), returns the latest-expiring token regardless of scope.
A character string specifying the tenant ID to filter tokens.
If NULL (default), matches any tenant.
A character string specifying the client ID to filter tokens.
If NULL (default), matches any client.
A character string specifying the Azure configuration
directory. Defaults to default_azure_config_dir().
The MSAL token cache is a JSON file maintained by the Azure CLI that stores access tokens and refresh tokens. This function reads cached access tokens directly from the file without invoking the Azure CLI, which can be useful in environments where the CLI is slow or unavailable but tokens have been previously cached.
When multiple tokens are found, the function selects the token that expires
latest. If scope is provided, only tokens matching that scope/resource are
returned.