Class AuthorizationCodeCredentialBuilder
- All Implemented Interfaces:
com.azure.core.client.traits.HttpTrait<AuthorizationCodeCredentialBuilder>
Fluent credential builder for instantiating a AuthorizationCodeCredential
.
Authorization Code authentication in Azure is a type of authentication mechanism that allows users to authenticate with Microsoft Entra ID and obtain an authorization code that can be used to request an access token to access Azure resources. It is a widely used authentication mechanism and is supported by a wide range of Azure services and applications. It provides a secure and scalable way to authenticate users and grant them access to Azure resources. The AuthorizationCodeCredential authenticates a user or an application and acquires a token with the configured authorization code and the redirectURL where authorization code was received.
Sample: Construct AuthorizationCodeCredential
The following code sample demonstrates the creation of a AuthorizationCodeCredential
,
using the AuthorizationCodeCredentialBuilder
to configure it.
The authorizationCode
, redirectUrl
and clientId
are required to be configured to create
AuthorizationCodeCredential
. 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 authorizationCodeCredential = new AuthorizationCodeCredentialBuilder() .authorizationCode("{authorization-code-received-at-redirectURL}") .redirectUrl("{redirectUrl-where-authorization-code-is-received}") .clientId("{clientId-of-application-being-authenticated") .build();
- See Also:
-
Constructor Summary
ConstructorDescriptionConstructs an instance of AuthorizationCodeCredentialBuilder. -
Method Summary
Modifier and TypeMethodDescriptionauthorizationCode
(String authCode) Sets the authorization code on the builder.build()
Creates a newAuthorizationCodeCredential
with the current configurations.clientSecret
(String clientSecret) Sets the client secret for the authentication.redirectUrl
(String redirectUrl) Sets redirect URL for the OAuth 2.0 login request, which must be registered as a valid redirect URL on the application.Methods inherited from class com.azure.identity.AadCredentialBuilderBase
additionallyAllowedTenants, additionallyAllowedTenants, authorityHost, clientId, disableInstanceDiscovery, enableUnsafeSupportLogging, executorService, tenantId
Methods inherited from class com.azure.identity.CredentialBuilderBase
addPolicy, clientOptions, configuration, enableAccountIdentifierLogging, httpClient, httpLogOptions, httpPipeline, maxRetry, pipeline, proxyOptions, retryOptions, retryPolicy, retryTimeout
-
Constructor Details
-
AuthorizationCodeCredentialBuilder
public AuthorizationCodeCredentialBuilder()Constructs an instance of AuthorizationCodeCredentialBuilder.
-
-
Method Details
-
authorizationCode
Sets the authorization code on the builder.- Parameters:
authCode
- the authorization code acquired from user login- Returns:
- the AuthorizationCodeCredentialBuilder itself
-
redirectUrl
Sets redirect URL for the OAuth 2.0 login request, which must be registered as a valid redirect URL on the application. The authorization code will be sent to this URL, so it must be listening on this server and is able to complete theAuthorizationCodeCredential
construction from there. This is also called Reply URLs in some contexts.- Parameters:
redirectUrl
- the redirect URL to send the authorization code- Returns:
- the AuthorizationCodeCredentialBuilder itself
-
clientSecret
Sets the client secret for the authentication. This is required for Microsoft Entra web apps.
Do not set this for Microsoft Entra native apps.
- Parameters:
clientSecret
- the secret value of the Microsoft Entra application.- Returns:
- An updated instance of this builder.
-
build
Creates a newAuthorizationCodeCredential
with the current configurations.- Returns:
- a
AuthorizationCodeCredential
with the current configurations.
-