Refresh token credential authentication
Source:R/credential-refresh-token.R
RefreshTokenCredential.RdAuthenticates using an existing refresh token. This credential is useful when you have obtained a refresh token through another authentication flow and want to use it to get new access tokens without interactive authentication.
Details
The refresh token credential uses the OAuth 2.0 refresh token flow to obtain new access tokens. It requires a valid refresh token that was previously obtained through an interactive flow (e.g., authorization code or device code).
This is particularly useful for:
Non-interactive sessions where you have a pre-obtained refresh token
Long-running applications that need to refresh tokens automatically
Scenarios where you want to avoid repeated interactive authentication
Methods
Inherited methods
Method new()
Create a new refresh token credential
Usage
RefreshTokenCredential$new(
refresh_token = default_refresh_token(),
scope = NULL,
tenant_id = NULL,
client_id = NULL
)Arguments
refresh_tokenA character string containing the refresh token. Defaults to
default_refresh_token()which reads from theAZURE_REFRESH_TOKENenvironment variable.scopeA character string specifying the OAuth2 scope. Defaults to
NULL.tenant_idA character string specifying the Azure Active Directory tenant ID. Defaults to
NULL.client_idA character string specifying the application (client) ID. Defaults to
NULL.
Method get_token()
Get an access token using the refresh token flow
Returns
An httr2::oauth_token() object containing the access token
Method req_auth()
Add OAuth refresh token authentication to an httr2 request
Arguments
reqAn
httr2::request()object
Examples
if (FALSE) { # \dontrun{
# Create credential with a refresh token
cred <- RefreshTokenCredential$new(
refresh_token = "your-refresh-token",
scope = "https://management.azure.com/.default",
tenant_id = "your-tenant-id",
client_id = "your-client-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))
} # }