B
Beacon Globe News

Class ChainedTokenCredential | Azure SDK for .NET

Author

Charlotte Adams

Published Feb 16, 2026

Provides a Azure.Core.TokenCredential implementation which chains multiple Azure.Core.TokenCredential implementations to be tried in order until one of the getToken methods returns a non-default Azure.Core.AccessToken.

Inheritance

Azure.Core.TokenCredential

ChainedTokenCredential

Namespace: System.Dynamic.ExpandoObject
Assembly: Azure.Identity.dll
Syntax
public class ChainedTokenCredential : Azure.Core.TokenCredential
Examples

The ChainedTokenCredential class provides the ability to link together multiple credential instances to be tried sequentially when authenticating. The following example demonstrates creating a credential which will attempt to authenticate using managed identity, and fall back to Azure CLI for authentication if a managed identity is unavailable in the current environment.

 // Authenticate using managed identity if it is available; otherwise use the Azure CLI to authenticate. var credential = new ChainedTokenCredential(new ManagedIdentityCredential(), new AzureCliCredential()); var eventHubProducerClient = new EventHubProducerClient("myeventhub.eventhubs.windows.net", "myhubpath", credential);

Constructors

ChainedTokenCredential(TokenCredential[])

Creates an instance with the specified Azure.Core.TokenCredential sources.

Declaration
public ChainedTokenCredential (params Azure.Core.TokenCredential[] sources);
Parameters

Methods

GetToken(TokenRequestContext, CancellationToken)

Sequentially calls Azure.Core.TokenCredential.GetToken(Azure.Core.TokenRequestContext,System.Threading.CancellationToken) on all the specified sources, returning the first successfully obtained Azure.Core.AccessToken. This method is called automatically by Azure SDK client libraries. You may call this method directly, but you must also handle token caching and token refreshing.

Declaration
public override Azure.Core.AccessToken GetToken (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = null);
Parameters
Azure.Core.TokenRequestContext requestContext

The details of the authentication request.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
Azure.Core.AccessToken

The first Azure.Core.AccessToken returned by the specified sources. Any credential which raises a CredentialUnavailableException will be skipped.

GetTokenAsync(TokenRequestContext, CancellationToken)

Sequentially calls Azure.Core.TokenCredential.GetToken(Azure.Core.TokenRequestContext,System.Threading.CancellationToken) on all the specified sources, returning the first successfully obtained Azure.Core.AccessToken. This method is called automatically by Azure SDK client libraries. You may call this method directly, but you must also handle token caching and token refreshing.

Declaration
[System.Diagnostics.DebuggerStepThrough]
public override System.Threading.Tasks.ValueTask<Azure.Core.AccessToken> GetTokenAsync (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = null);
Parameters
Azure.Core.TokenRequestContext requestContext

The details of the authentication request.

System.Threading.CancellationToken cancellationToken

A System.Threading.CancellationToken controlling the request lifetime.

Returns
System.Threading.Tasks.ValueTask<Azure.Core.AccessToken>

The first Azure.Core.AccessToken returned by the specified sources. Any credential which raises a CredentialUnavailableException will be skipped.