Class UsernamePasswordCredential
- All Implemented Interfaces:
com.azure.core.credential.TokenCredential
Username password authentication is a common type of authentication flow used by many applications and services, including Azure Active Directory (Azure AD) . 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.
In the scenario where 2FA/MFA (Multi-factored) authentication is turned on, please use
DeviceCodeCredential
or InteractiveBrowserCredential
instead.
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();
-
Method Summary
Modifier and TypeMethodDescriptionAuthenticates the user using the specified username and password.authenticate
(com.azure.core.credential.TokenRequestContext request) Authenticates the user using the specified username and password.Mono<com.azure.core.credential.AccessToken>
getToken
(com.azure.core.credential.TokenRequestContext request) com.azure.core.credential.AccessToken
getTokenSync
(com.azure.core.credential.TokenRequestContext request)
-
Method Details
-
getToken
public Mono<com.azure.core.credential.AccessToken> getToken(com.azure.core.credential.TokenRequestContext request) - Specified by:
getToken
in interfacecom.azure.core.credential.TokenCredential
-
getTokenSync
public com.azure.core.credential.AccessToken getTokenSync(com.azure.core.credential.TokenRequestContext request) - Specified by:
getTokenSync
in interfacecom.azure.core.credential.TokenCredential
-
authenticate
public Mono<AuthenticationRecord> authenticate(com.azure.core.credential.TokenRequestContext request) Authenticates the user using the specified username and password.- Parameters:
request
- The details of the authentication request.- Returns:
- The
AuthenticationRecord
of the authenticated account.
-
authenticate
Authenticates the user using the specified username and password.- Returns:
- The
AuthenticationRecord
of the authenticated account.
-