ClientSecretCredential: Client secret credential authentication

ClientSecretCredentialR Documentation

Client secret credential authentication

Description

Authenticates a service principal using a client ID and client secret. This credential is commonly used for application authentication in Azure.

Details

The credential uses the OAuth 2.0 client credentials flow to obtain access tokens. It requires a registered Azure AD application with a client secret. The client secret should be stored securely and not hard-coded in scripts.

Super class

azr::Credential -> ClientSecretCredential

Methods

Public methods

Inherited methods

Method validate()

Validate the credential configuration

Usage
ClientSecretCredential$validate()
Details

Checks that the client secret is provided and not NA or NULL. Calls the parent class validation method.


Method get_token()

Get an access token using client credentials flow

Usage
ClientSecretCredential$get_token()
Returns

An httr2::oauth_token() object containing the access token


Method req_auth()

Add OAuth client credentials authentication to an httr2 request

Usage
ClientSecretCredential$req_auth(req)
Arguments
req

An httr2::request() object

Returns

The request object with OAuth client credentials authentication configured


Method clone()

The objects of this class are cloneable with this method.

Usage
ClientSecretCredential$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

# Create credential with client secret
cred <- ClientSecretCredential$new(
  tenant_id = "your-tenant-id",
  client_id = "your-client-id",
  client_secret = "your-client-secret",
  scope = "https://management.azure.com/.default"
)

# To get a token or authenticate a request it requires
# valid 'client_id' and 'client_secret' credentials,
# otherwise it will return an error.
## Not run: 
# 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))

## End(Not run)

azr documentation built on Feb. 18, 2026, 1:07 a.m.