
Managed identity credential authentication
Source:R/credential-managed-identity.R
ManagedIdentityCredential.RdAuthenticates using an Azure managed identity. Supports both system-assigned and user-assigned managed identities. This credential works when code is running inside an Azure environment that has a managed identity configured (e.g., VMs, App Service, Container Instances, AKS pods).
Details
Authentication is performed by querying the Azure Instance Metadata Service
(IMDS) endpoint at http://169.254.169.254/metadata/identity/oauth2/token.
No credentials need to be stored — the identity is granted by the Azure
platform.
To use a system-assigned managed identity, leave client_id as NULL.
To use a user-assigned managed identity, supply its client_id.
This credential fails immediately (2-second timeout) when not running inside Azure, so it is safe to include early in a credential chain.
Public fields
.msi_client_idClient ID for user-assigned managed identity, or
NULLfor system-assigned.
Methods
Method new()
Create a new managed identity credential
Usage
ManagedIdentityCredential$new(scope = NULL, client_id = NULL)Method get_token()
Get an access token from the IMDS endpoint
Details
Returns a valid in-object cached token immediately if one exists. Otherwise queries the Azure Instance Metadata Service (IMDS) for a new token.
Returns
An httr2::oauth_token() object containing the access token
Method req_auth()
Add managed identity authentication to an httr2 request
Arguments
reqAn
httr2::request()object
Examples
if (FALSE) { # \dontrun{
# System-assigned managed identity (no client_id needed)
cred <- ManagedIdentityCredential$new(
scope = "https://management.azure.com/.default"
)
# User-assigned managed identity
cred <- ManagedIdentityCredential$new(
scope = "https://management.azure.com/.default",
client_id = "your-user-assigned-client-id"
)
token <- cred$get_token()
} # }