ChainedTokenCredential Class
Definition
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.
public class ChainedTokenCredential : Azure.Core.TokenCredential
type ChainedTokenCredential = class
inherit TokenCredential
Public Class ChainedTokenCredential
Inherits TokenCredential
- Inheritance
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 TokenCredential sources. |
Methods
| GetToken(TokenRequestContext, CancellationToken) |
Sequentially calls GetToken(TokenRequestContext, CancellationToken) on all the specified sources, returning the first successfully obtained 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. |
| GetTokenAsync(TokenRequestContext, CancellationToken) |
Sequentially calls GetToken(TokenRequestContext, CancellationToken) on all the specified sources, returning the first successfully obtained 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. |
Applies to
Saran dan Komentar
Kirim dan lihat umpan balik untuk