Package com.azure.identity
Class ChainedTokenCredential
java.lang.Object
com.azure.identity.ChainedTokenCredential
- All Implemented Interfaces:
com.azure.core.credential.TokenCredential
- Direct Known Subclasses:
DefaultAzureCredential
public class ChainedTokenCredential
extends Object
implements com.azure.core.credential.TokenCredential
A token credential provider that can provide a credential from a list of providers.
Sample: Construct a ChainedTokenCredential with silent username+password login tried first, then interactive browser login as needed (e.g. when 2FA is turned on in the directory).
UsernamePasswordCredential usernamePasswordCredential = new UsernamePasswordCredentialBuilder()
.clientId(clientId)
.username(fakeUsernamePlaceholder)
.password(fakePasswordPlaceholder)
.build();
InteractiveBrowserCredential interactiveBrowserCredential = new InteractiveBrowserCredentialBuilder()
.clientId(clientId)
.port(8765)
.build();
ChainedTokenCredential credential = new ChainedTokenCredentialBuilder()
.addLast(usernamePasswordCredential)
.addLast(interactiveBrowserCredential)
.build();
-
Method Summary
Modifier and TypeMethodDescriptionMono<com.azure.core.credential.AccessToken>getToken(com.azure.core.credential.TokenRequestContext request) Sequentially callsTokenCredential.getToken(TokenRequestContext)on all the specified credentials, returning the first successfully obtainedAccessToken.com.azure.core.credential.AccessTokengetTokenSync(com.azure.core.credential.TokenRequestContext request)
-
Method Details
-
getToken
public Mono<com.azure.core.credential.AccessToken> getToken(com.azure.core.credential.TokenRequestContext request) Sequentially callsTokenCredential.getToken(TokenRequestContext)on all the specified credentials, returning the first successfully obtainedAccessToken. 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.- Specified by:
getTokenin interfacecom.azure.core.credential.TokenCredential- Parameters:
request- the details of the token request- Returns:
- a Publisher that emits a single access token
-
getTokenSync
public com.azure.core.credential.AccessToken getTokenSync(com.azure.core.credential.TokenRequestContext request) - Specified by:
getTokenSyncin interfacecom.azure.core.credential.TokenCredential
-