<PackageReference Include="Azure.Core" Version="1.53.0" />

Azure.Identity.UsernamePasswordCredential

Enables authentication to Microsoft Entra ID 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.

Protected constructor for mocking

public UsernamePasswordCredential(string username, string password, string tenantId, string clientId)

Creates an instance of the UsernamePasswordCredential with the details needed to authenticate against Microsoft Entra ID with a simple username and password.

public UsernamePasswordCredential(string username, string password, string tenantId, string clientId, TokenCredentialOptions options)

Creates an instance of the UsernamePasswordCredential with the details needed to authenticate against Microsoft Entra ID with a simple username and password.

public UsernamePasswordCredential(string username, string password, string tenantId, string clientId, UsernamePasswordCredentialOptions options)

Creates an instance of the UsernamePasswordCredential with the details needed to authenticate against Microsoft Entra ID with a simple username and password.

public virtual AuthenticationRecord Authenticate(CancellationToken cancellationToken = default)

Authenticates the user using the specified username and password.

public virtual AuthenticationRecord Authenticate(TokenRequestContext requestContext, CancellationToken cancellationToken = default)

Authenticates the user using the specified username and password.

public virtual Task<AuthenticationRecord> AuthenticateAsync(CancellationToken cancellationToken = default)

Authenticates the user using the specified username and password.

public virtual Task<AuthenticationRecord> AuthenticateAsync(TokenRequestContext requestContext, CancellationToken cancellationToken = default)

Authenticates the user using the specified username and password.