你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

ChainedTokenCredential Class

A sequence of credentials that is itself a credential.

Its get_token method calls get_token on each credential in the sequence, in order, returning the first valid token received.

Constructor

Python
ChainedTokenCredential(*credentials: TokenCredential)

Parameters

Name Description
credentials
Required

credential instances to form the chain

Examples

Create a ChainedTokenCredential.

Python

   from azure.identity import ChainedTokenCredential, EnvironmentCredential, AzureCliCredential

   credential_chain = (
       # Try EnvironmentCredential first
       EnvironmentCredential(),
       # Fallback to Azure CLI if EnvironmentCredential fails
       AzureCliCredential(),
   )
   credential = ChainedTokenCredential(*credential_chain)

Methods

close

Close the transport session of each credential in the chain.

get_token

Request a token from each chained credential, in order, returning the first token received.

This method is called automatically by Azure SDK clients.

close

Close the transport session of each credential in the chain.

Python
close() -> None

get_token

Request a token from each chained credential, in order, returning the first token received.

This method is called automatically by Azure SDK clients.

Python
get_token(*scopes: str, claims: str | None = None, tenant_id: str | None = None, **kwargs: Any) -> AccessToken

Parameters

Name Description
scopes
Required
str

desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.

Keyword-Only Parameters

Name Description
claims
str

additional claims required in the token, such as those returned in a resource provider's claims challenge following an authorization failure.

tenant_id
str

optional tenant to include in the token request.

Returns

Type Description

An access token with the desired scopes.

Exceptions

Type Description

no credential in the chain provided a token