Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
ChainedTokenCredential Class
Definition
- Namespace:
- Azure.Identity
- Assemblies:
- Azure.Core.dll, Azure.Identity.dll
- Assembly:
- Azure.Identity.dll
- Packages:
- Azure.Core v1.58.0, Azure.Identity v1.17.2
- Package:
- Azure.Identity v1.18.0-beta.3
- Source:
- ChainedTokenCredential.cs
- Source:
- ChainedTokenCredential.cs
Important
Some information relates to prerelease product that may be substantially modified before itβs released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides a TokenCredential implementation which chains multiple TokenCredential implementations to be tried in order until one of the GetToken methods returns a non-default AccessToken. For more information, see ChainedTokenCredential overview.
public class ChainedTokenCredential : Azure.Core.TokenCredential
type ChainedTokenCredential = class
inherit TokenCredential
Public Class ChainedTokenCredential
Inherits TokenCredential
- Inheritance
Examples
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
| Name | Description |
|---|---|
| ChainedTokenCredential() |
Protected constructor for mocking. |
| ChainedTokenCredential(TokenCredential[]) |
Creates an instance with the specified TokenCredential sources. |
Methods
| Name | Description |
|---|---|
| CreateTokenOptions(IReadOnlyDictionary<String,Object>) |
Creates a new instance of GetTokenOptions using the provided |
| GetToken(GetTokenOptions, CancellationToken) |
Gets an AuthenticationToken for the provided |
| GetToken(TokenRequestContext, CancellationToken) |
Sequentially calls GetToken(TokenRequestContext, CancellationToken) on all the specified sources, returning the first successfully obtained AccessToken. Acquired tokens are cached by the credential instance. Token lifetime and refreshing is handled automatically. Where possible, reuse credential instances to optimize cache effectiveness. |
| GetTokenAsync(GetTokenOptions, CancellationToken) |
Gets an AuthenticationToken for the provided |
| GetTokenAsync(TokenRequestContext, CancellationToken) |
Sequentially calls GetToken(TokenRequestContext, CancellationToken) on all the specified sources, returning the first successfully obtained AccessToken. Acquired tokens are cached by the credential instance. Token lifetime and refreshing is handled automatically. Where possible, reuse credential instances to optimize cache effectiveness. |
Applies to
Azure SDK for .NET
Feedback
Was this page helpful?
