ChainedTokenCredential Class
- java.lang.Object
- com.azure.identity.ChainedTokenCredential
Implements
public class ChainedTokenCredential
implements 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 Type | Method and Description |
---|---|
getToken(TokenRequestContext request)
Sequentially calls TokenCredential#getToken(TokenRequestContext) on all the specified credentials, returning the first successfully obtained AccessToken. |
|
AccessToken | getTokenSync(TokenRequestContext request) |
Methods inherited from java.lang.Object
Method Details
getToken
public Mono
Sequentially calls TokenCredential#getToken(TokenRequestContext) on all the specified credentials, 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.
Parameters:
Returns:
getTokenSync
public AccessToken getTokenSync(TokenRequestContext request)
Parameters: