UsernamePasswordCredentialBuilder Class
- java.
lang. Object - com.
azure. identity. CredentialBuilderBase<T> - com.
azure. identity. AadCredentialBuilderBase<T> - com.
azure. identity. UsernamePasswordCredentialBuilder
- com.
- com.
- com.
public class UsernamePasswordCredentialBuilder
extends AadCredentialBuilderBase<UsernamePasswordCredentialBuilder>
Fluent credential builder for instantiating a UsernamePasswordCredential.
Username password authentication is a common type of authentication flow used by many applications and services, including Microsoft Entra ID. With username password authentication, users enter their username and password credentials to sign in to an application or service. The UsernamePasswordCredential authenticates a public client application and acquires a token using the user credentials that don't require 2FA/MFA (Multi-factored) authentication. For more information refer to the conceptual knowledge and configuration details.
Sample: Construct UsernamePasswordCredential
The following code sample demonstrates the creation of a UsernamePasswordCredential, using the UsernamePasswordCredentialBuilder to configure it. The clientId
, username
and password
parameters are required to create UsernamePasswordCredential. 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(
"<your app client ID>").username("<your username>").password("<your password>").build();
Constructor Summary
Constructor | Description |
---|---|
UsernamePasswordCredentialBuilder() |
Constructs an instance of Username |
Method Summary
Modifier and Type | Method and Description |
---|---|
Username |
additionallyAllowedTenants(String[] additionallyAllowedTenants)
For multi-tenant applications, specifies additional tenants for which the credential may acquire tokens. |
Username |
additionallyAllowedTenants(List<String> additionallyAllowedTenants)
For multi-tenant applications, specifies additional tenants for which the credential may acquire tokens. |
Username |
build()
Creates a new UsernamePasswordCredential with the current configurations. |
Username |
password(String password)
Sets the password of the user. |
Username |
tokenCachePersistenceOptions(TokenCachePersistenceOptions tokenCachePersistenceOptions)
Configures the persistent shared token cache options and enables the persistent token cache which is disabled by default. |
Username |
username(String username)
Sets the username of the user. |
Methods inherited from AadCredentialBuilderBase
Methods inherited from CredentialBuilderBase
Methods inherited from java.lang.Object
Constructor Details
UsernamePasswordCredentialBuilder
public UsernamePasswordCredentialBuilder()
Constructs an instance of UsernamePasswordCredentialBuilder.
Method Details
additionallyAllowedTenants
public UsernamePasswordCredentialBuilder additionallyAllowedTenants(String[] additionallyAllowedTenants)
For multi-tenant applications, specifies additional tenants for which the credential may acquire tokens. Add the wildcard value "*" to allow the credential to acquire tokens for any tenant on which the application is installed. If no value is specified for TenantId this option will have no effect, and the credential will acquire tokens for any requested tenant.
Overrides:
UsernamePasswordCredentialBuilder.additionallyAllowedTenants(String[] additionallyAllowedTenants)Parameters:
Returns:
additionallyAllowedTenants
public UsernamePasswordCredentialBuilder additionallyAllowedTenants(List
For multi-tenant applications, specifies additional tenants for which the credential may acquire tokens. Add the wildcard value "*" to allow the credential to acquire tokens for any tenant on which the application is installed. If no value is specified for TenantId this option will have no effect, and the credential will acquire tokens for any requested tenant.
Overrides:
UsernamePasswordCredentialBuilder.additionallyAllowedTenants(List<String> additionallyAllowedTenants)Parameters:
Returns:
build
public UsernamePasswordCredential build()
Creates a new UsernamePasswordCredential with the current configurations.
Returns:
password
public UsernamePasswordCredentialBuilder password(String password)
Sets the password of the user.
Parameters:
Returns:
tokenCachePersistenceOptions
public UsernamePasswordCredentialBuilder tokenCachePersistenceOptions(TokenCachePersistenceOptions tokenCachePersistenceOptions)
Configures the persistent shared token cache options and enables the persistent token cache which is disabled by default. If configured, the credential will store tokens in a cache persisted to the machine, protected to the current user, which can be shared by other credentials and processes.
Parameters:
Returns:
username
public UsernamePasswordCredentialBuilder username(String username)
Sets the username of the user.
Parameters:
Returns:
Applies to
Azure SDK for Java