Class BasicAuthenticationCredential
- All Implemented Interfaces:
TokenCredential
The BasicAuthenticationCredential is used to authenticate and authorize requests made to
Azure services using the Basic authentication scheme. Basic Authentication is a simple authentication scheme
that uses a combination of a username and password.
Note that Basic Authentication is generally considered less secure than other authentication methods,
such as Azure Active Directory (AAD) authentication. It is recommended to use
Azure Active Directory (Azure AD)
authentication via TokenCredential whenever possible, especially for production environments.
Sample: Azure SAS Authentication
The following code sample demonstrates the creation of a
BasicAuthenticationCredential, using username and password
BasicAuthenticationCredential basicAuthenticationCredential =
new BasicAuthenticationCredential("<username>", "<password>");
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBasicAuthenticationCredential(String username, String password) Creates a basic authentication credential. -
Method Summary
Modifier and TypeMethodDescriptiongetToken(TokenRequestContext request) Asynchronously get a token for a given resource/audience.getTokenSync(TokenRequestContext request) Synchronously get a token for a given resource/audience.
-
Constructor Details
-
BasicAuthenticationCredential
Creates a basic authentication credential.- Parameters:
username- basic auth usernamepassword- basic auth password
-
-
Method Details
-
getToken
Description copied from interface:TokenCredentialAsynchronously get a token for a given resource/audience.This method is called automatically by Azure SDK client libraries.
You may call this method directly, but you must also handle token caching and token refreshing.
- Specified by:
getTokenin interfaceTokenCredential- Parameters:
request- the details of the token request- Returns:
- a Publisher that emits a single access token
-
getTokenSync
Description copied from interface:TokenCredentialSynchronously get a token for a given resource/audience.This method is called automatically by Azure SDK client libraries.
You may call this method directly, but you must also handle token caching and token refreshing.
- Specified by:
getTokenSyncin interfaceTokenCredential- Parameters:
request- the details of the token request- Returns:
- The Access Token
-