An R6 class that provides lazy initialization of credential providers. The credential provider is created on first access using the default credential chain.
Details
This class wraps the credential discovery process in an R6 object with
a lazily evaluated provider field. The provider is only created when
first accessed, using the same logic as get_token_provider().
Public fields
.scopeCharacter string specifying the authentication scope.
.tenant_idCharacter string specifying the tenant ID.
.client_idCharacter string specifying the client ID.
.client_secretCharacter string specifying the client secret.
.use_cacheCharacter string indicating the caching strategy.
.offlineLogical indicating whether to request offline access.
.chainA credential chain object for authentication.
Methods
Method new()
Create a new DefaultCredential object
Usage
DefaultCredential$new(
scope = NULL,
tenant_id = NULL,
client_id = NULL,
client_secret = NULL,
use_cache = "disk",
offline = TRUE,
chain = default_credential_chain()
)Arguments
scopeOptional character string specifying the authentication scope.
tenant_idOptional character string specifying the tenant ID for authentication.
client_idOptional character string specifying the client ID for authentication.
client_secretOptional character string specifying the client secret for authentication.
use_cacheCharacter string indicating the caching strategy. Defaults to
"disk". Options include"disk"for disk-based caching or"memory"for in-memory caching.offlineLogical. If
TRUE, adds 'offline_access' to the scope to request a 'refresh_token'. Defaults toTRUE.chainA list of credential objects, where each element must inherit from the
Credentialbase class. Credentials are attempted in the order provided untilget_tokensucceeds.
Method get_token()
Get an access token using the credential chain
Returns
An httr2::oauth_token() object containing the access token
Examples
# Create a DefaultCredential object
cred <- DefaultCredential$new(
scope = "https://graph.microsoft.com/.default",
tenant_id = "my-tenant-id"
)
if (FALSE) { # \dontrun{
# Get a token (triggers lazy initialization)
token <- cred$get_token()
# Authenticate a request
req <- httr2::request("https://management.azure.com/subscriptions")
resp <- httr2::req_perform(cred$req_auth(req))
# Or access the provider directly
provider <- cred$provider
} # }