ChainedTokenCredentialBuilder Class

  • java.lang.Object
    • com.azure.identity.ChainedTokenCredentialBuilder

public class ChainedTokenCredentialBuilder

Fluent credential builder for instantiating ChainedTokenCredential.

Sample: Construct a ChainedTokenCredential.

The following code sample demonstrates the creation of a ChainedTokenCredential, using the ChainedTokenCredentialBuilder to configure it. The sample below tries silent username+password login tried first, then interactive browser login as needed (e.g. when 2FA is turned on in the directory). Once this credential is created, it may be passed into the builder of many of the Azure SDK for Java client builders as the 'credential' parameter.

TokenCredential usernamePasswordCredential = new UsernamePasswordCredentialBuilder().clientId(clientId)
     .username(fakeUsernamePlaceholder)
     .password(fakePasswordPlaceholder)
     .build();
 TokenCredential interactiveBrowserCredential = new InteractiveBrowserCredentialBuilder().clientId(clientId)
     .port(8765)
     .build();
 TokenCredential credential = new ChainedTokenCredentialBuilder().addLast(usernamePasswordCredential)
     .addLast(interactiveBrowserCredential)
     .build();

Constructor Summary

Constructor Description
ChainedTokenCredentialBuilder()

Creates an instance of the builder to config the credential.

Method Summary

Modifier and Type Method and Description
ChainedTokenCredentialBuilder addAll(Collection<? extends TokenCredential> credentials)

Adds all of the credentials in the specified collection at the end of this chain, as if by calling addLast(TokenCredential credential) on each one, in the order that they are returned by the collection's iterator.

ChainedTokenCredentialBuilder addFirst(TokenCredential credential)

Adds a credential to try to authenticate at the front of the chain.

ChainedTokenCredentialBuilder addLast(TokenCredential credential)

Adds a credential to try to authenticate at the last of the chain.

ChainedTokenCredential build()

Creates a new ChainedTokenCredential with the current configurations.

Methods inherited from java.lang.Object

Constructor Details

ChainedTokenCredentialBuilder

public ChainedTokenCredentialBuilder()

Creates an instance of the builder to config the credential.

Method Details

addAll

public ChainedTokenCredentialBuilder addAll(Collection credentials)

Adds all of the credentials in the specified collection at the end of this chain, as if by calling addLast(TokenCredential credential) on each one, in the order that they are returned by the collection's iterator.

Parameters:

credentials - the collection of credentials to be appended to the chain.

Returns:

An updated instance of the builder.

addFirst

public ChainedTokenCredentialBuilder addFirst(TokenCredential credential)

Adds a credential to try to authenticate at the front of the chain.

Parameters:

credential - the credential to be added to the front of chain

Returns:

the ChainedTokenCredential itself

addLast

public ChainedTokenCredentialBuilder addLast(TokenCredential credential)

Adds a credential to try to authenticate at the last of the chain.

Parameters:

credential - the credential to be added to the end of chain

Returns:

the ChainedTokenCredential itself

build

public ChainedTokenCredential build()

Creates a new ChainedTokenCredential with the current configurations.

Returns:

a ChainedTokenCredential with the current configurations.

Applies to