Class UsernamePasswordCredential
Enables authentication to Azure Active Directory using a user's username and password. If the user has MFA enabled this credential will fail to get a token throwing an AuthenticationFailedException. Also, this credential requires a high degree of trust and is not recommended outside of prototyping when more secure credentials can be used.
Namespace: Azure.Identity
Assembly: Azure.Identity.dll
Syntax
public class UsernamePasswordCredential : Azure.Core.TokenCredential
Constructors
UsernamePasswordCredential()
Protected constructor for mocking
Declaration
protected UsernamePasswordCredential ();
UsernamePasswordCredential(String, String, String, String)
Creates an instance of the UsernamePasswordCredential with the details needed to authenticate against Azure Active Directory with a simple username and password.
Declaration
public UsernamePasswordCredential (string username, string password, string tenantId, string clientId);
Parameters
String
username
|
String
password
The user account's username, also known as UPN. |
String
tenantId
The Azure Active Directory tenant (directory) ID or name. |
String
clientId
The client (application) ID of an App Registration in the tenant. |
UsernamePasswordCredential(String, String, String, String, TokenCredentialOptions)
Creates an instance of the UsernamePasswordCredential with the details needed to authenticate against Azure Active Directory with a simple username and password.
Declaration
public UsernamePasswordCredential (string username, string password, string tenantId, string clientId, Azure.Identity.TokenCredentialOptions options);
Parameters
String
username
|
String
password
The user account's user name, UPN. |
String
tenantId
The Azure Active Directory tenant (directory) ID or name. |
String
clientId
The client (application) ID of an App Registration in the tenant. |
TokenCredentialOptions
options
The client options for the newly created UsernamePasswordCredential |
Methods
GetToken(TokenRequestContext, CancellationToken)
Obtains a token for a user account, authenticating them using the given username and password. Note: This will fail with an AuthenticationFailedException if the specified user account has MFA enabled. This method is called by Azure SDK clients. It isn't intended for use in application code.
Declaration
public override Azure.Core.AccessToken GetToken (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = null);
Parameters
Azure.Core.TokenRequestContext
requestContext
The details of the authentication request. |
CancellationToken
cancellationToken
A CancellationToken controlling the request lifetime. |
Returns
AccessToken
An AccessToken which can be used to authenticate service client calls. |
GetTokenAsync(TokenRequestContext, CancellationToken)
Obtains a token for a user account, authenticating them using the given username and password. Note: This will fail with an AuthenticationFailedException if the specified user account has MFA enabled. This method is called by Azure SDK clients. It isn't intended for use in application code.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public override System.Threading.Tasks.ValueTask<Azure.Core.AccessToken> GetTokenAsync (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = null);
Parameters
Azure.Core.TokenRequestContext
requestContext
The details of the authentication request. |
CancellationToken
cancellationToken
A CancellationToken controlling the request lifetime. |
Returns
ValueTask<AccessToken>
An AccessToken which can be used to authenticate service client calls. |