pub struct ManagedIdentityCredential { /* private fields */ }Expand description
Authenticates via an Azure Managed Identity by calling the Instance Metadata
Service (IMDS) token endpoint
(GET {endpoint}?api-version=2018-02-01&resource=<resource> with the
Metadata: true header).
The endpoint defaults to the IMDS address but is overridden from the
IDENTITY_ENDPOINT/MSI_ENDPOINT environment variables (as set by App
Service / Functions) or via with_endpoint — which
also makes it loopback-testable. An optional user-assigned identity client
id may be supplied.
Implementations§
Source§impl ManagedIdentityCredential
impl ManagedIdentityCredential
Sourcepub fn new(scope: impl Into<String>) -> Self
pub fn new(scope: impl Into<String>) -> Self
Create a managed-identity credential acquiring tokens for scope.
The IMDS endpoint is taken from IDENTITY_ENDPOINT, then MSI_ENDPOINT,
then DEFAULT_IMDS_ENDPOINT; an IDENTITY_HEADER, when present, is
forwarded as X-IDENTITY-HEADER.
Sourcepub fn with_endpoint(self, endpoint: impl Into<String>) -> Self
pub fn with_endpoint(self, endpoint: impl Into<String>) -> Self
Override the token endpoint (default DEFAULT_IMDS_ENDPOINT or the
environment) — the seam used by loopback tests.
Sourcepub fn with_client_id(self, client_id: impl Into<String>) -> Self
pub fn with_client_id(self, client_id: impl Into<String>) -> Self
Pin a user-assigned managed identity by its client id.
Sourcepub fn with_identity_header(self, header: impl Into<String>) -> Self
pub fn with_identity_header(self, header: impl Into<String>) -> Self
Set the X-IDENTITY-HEADER value (App Service / Functions secret).
Trait Implementations§
Source§impl TokenCredential for ManagedIdentityCredential
impl TokenCredential for ManagedIdentityCredential
Source§fn get_token<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_token<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Authorization: Bearer <token>.Source§fn get_token_for_scope<'life0, 'life1, 'async_trait>(
&'life0 self,
scope: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_token_for_scope<'life0, 'life1, 'async_trait>(
&'life0 self,
scope: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
scope (audience), e.g.
"https://ai.azure.com/.default". Read more