Authenticates using the Azure CLI (az) command-line tool. This credential
requires the Azure CLI to be installed and the user to be logged in via
az login.
Details
The credential uses the az account get-access-token command to retrieve
access tokens. It will use the currently active Azure CLI account and
subscription unless a specific tenant is specified.
Public fields
auto_loginLogical indicating whether to check login status and perform login if needed
use_bridgeLogical indicating whether to use the device code bridge webpage during interactive login
.process_timeoutTimeout in seconds for Azure CLI command execution
Methods
Inherited methods
Method new()
Create a new Azure CLI credential
Usage
AzureCLICredential$new(
scope = NULL,
tenant_id = NULL,
process_timeout = NULL,
auto_login = opts$get("cli_auto_login"),
use_bridge = TRUE,
interactive = NULL
)Arguments
scopeA character string specifying the OAuth2 scope. Defaults to
NULL, which uses the scope set during initialization.tenant_idA character string specifying the Azure Active Directory tenant ID. Defaults to
NULL, which uses the default tenant from Azure CLI.process_timeoutA numeric value specifying the timeout in seconds for the Azure CLI process. Defaults to
10.auto_loginA logical value indicating whether
get_token()may launchaz loginwhen the user is not logged in. Defaults to thecli_auto_loginoption (options(azr.cli_auto_login = ...)orAZR_CLI_AUTO_LOGIN); seeazr_options().use_bridgeA logical value indicating whether to use the device code bridge webpage during login. If
TRUE, launches an intermediate local webpage that displays the device code and facilitates copy-pasting before redirecting to the Microsoft device login page. Only used whenauto_login = TRUE. Defaults toTRUE.interactiveDeprecated. Use
auto_logininstead.
Method get_token()
Get an access token from Azure CLI
Arguments
scopeA character string specifying the OAuth2 scope. If
NULL, uses the scope specified during initialization.
Returns
An httr2::oauth_token() object containing the access token
Method req_auth()
Add authentication to an httr2 request
Arguments
reqAn
httr2::request()objectscopeA character string specifying the OAuth2 scope. If
NULL, uses the scope specified during initialization.
Method account_show()
Show the currently active Azure CLI account information
Examples
# 'az login' must have been executed successfully for these examples to work.
if (FALSE) { # \dontrun{
# Create credential with default settings
cred <- AzureCLICredential$new()
# Create credential with specific scope and tenant
cred <- AzureCLICredential$new(
scope = "https://management.azure.com/.default",
tenant_id = "your-tenant-id"
)
# Get an access token
token <- cred$get_token()
# Use with httr2 request
req <- httr2::request("https://management.azure.com/subscriptions")
resp <- httr2::req_perform(cred$req_auth(req))
} # }
