| DefaultCredential | R Documentation |
An R6 class that provides lazy initialization of credential providers. The credential provider is created on first access using the default credential chain.
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().
.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.
providerLazily initialized credential provider
new()Create a new DefaultCredential object
DefaultCredential$new( scope = NULL, tenant_id = NULL, client_id = NULL, client_secret = NULL, use_cache = "disk", offline = TRUE, chain = default_credential_chain() )
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 to TRUE.
chainA list of credential objects, where each element must inherit
from the Credential base class. Credentials are attempted in the order
provided until get_token succeeds.
A new DefaultCredential object
get_token()Get an access token using the credential chain
DefaultCredential$get_token()
An httr2::oauth_token() object containing the access token
req_auth()Add authentication to an httr2 request
DefaultCredential$req_auth(req)
reqAn httr2::request() object
The request object with authentication configured
clone()The objects of this class are cloneable with this method.
DefaultCredential$clone(deep = FALSE)
deepWhether to make a deep clone.
# Create a DefaultCredential object
cred <- DefaultCredential$new(
scope = "https://graph.microsoft.com/.default",
tenant_id = "my-tenant-id"
)
## Not run:
# 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
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.