| CachedTokenCredential | R Documentation |
A credential class that retrieves tokens from the cache only, without triggering interactive authentication flows. This is useful for non-interactive sessions where you want to use previously cached tokens from DeviceCode or AuthCode credentials.
This credential attempts to retrieve cached tokens from a chain of interactive credentials (AuthCode and DeviceCode by default). It will not prompt for new authentication - it only returns tokens that are already cached.
This is particularly useful for:
Non-interactive R sessions (e.g., scheduled scripts, CI/CD)
Scenarios where you've previously authenticated interactively and want to reuse those cached tokens
.scopeCharacter string specifying the authentication scope.
.tenant_idCharacter string specifying the tenant ID.
.client_idCharacter string specifying the client ID.
.chainList of credential classes to attempt for cached tokens.
providerLazily initialized credential provider
new()Create a new CachedTokenCredential object
CachedTokenCredential$new( scope = NULL, tenant_id = NULL, client_id = NULL, chain = cached_token_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.
chainA list of credential classes to attempt for cached tokens. Defaults to AuthCodeCredential and DeviceCodeCredential.
A new CachedTokenCredential object
get_token()Get an access token from the cache
CachedTokenCredential$get_token()
An httr2::oauth_token() object containing the access token
req_auth()Add authentication to an httr2 request
CachedTokenCredential$req_auth(req)
reqAn httr2::request() object
The request object with authentication configured
clone()The objects of this class are cloneable with this method.
CachedTokenCredential$clone(deep = FALSE)
deepWhether to make a deep clone.
## Not run:
# Create credential with default settings
cred <- CachedTokenCredential$new(
scope = "https://graph.microsoft.com/.default",
tenant_id = "my-tenant-id"
)
# Get a cached token (will fail if no cached token exists)
token <- cred$get_token()
# Use with httr2 request
req <- httr2::request("https://graph.microsoft.com/v1.0/me")
req <- cred$req_auth(req)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.