Client secret credential authentication
Source:R/credential-client-secret.R
ClientSecretCredential.RdAuthenticates 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.
Methods
Method get_token()
Get an access token using client credentials flow
Returns
An httr2::oauth_token() object containing the access token
Method req_auth()
Add OAuth client credentials authentication to an httr2 request
Arguments
reqAn
httr2::request()object
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.
if (FALSE) { # \dontrun{
# 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))
} # }