View source: R/credential-azure-cli.R
| az_cli_get_cached_token | R Documentation |
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()
)
scope |
A character string specifying the OAuth2 scope to filter tokens.
If |
tenant_id |
A character string specifying the tenant ID to filter tokens.
If |
client_id |
A character string specifying the client ID to filter tokens.
If |
config_dir |
A character string specifying the Azure configuration
directory. Defaults to |
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.
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
## Not run:
# Get any cached token
token <- az_cli_get_cached_token()
# Get a cached token for a specific scope
token <- az_cli_get_cached_token(
scope = "https://management.azure.com/.default"
)
# Access the token string
token$access_token
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.