
com.azure.identity.credential.ClientSecretCredential Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-identity Show documentation
Show all versions of azure-identity Show documentation
This module contains client library for Microsoft Azure Identity.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.identity.credential;
import com.azure.core.annotation.Immutable;
import com.azure.core.credentials.AccessToken;
import com.azure.core.credentials.TokenCredential;
import com.azure.core.credentials.TokenRequest;
import com.azure.identity.implementation.IdentityClient;
import com.azure.identity.implementation.IdentityClientBuilder;
import com.azure.identity.implementation.IdentityClientOptions;
import reactor.core.publisher.Mono;
import java.util.Objects;
/**
* An AAD credential that acquires a token with a client secret for an AAD application.
*
* Sample: Construct a simple ClientSecretCredential
* {@codesnippet com.azure.identity.credential.clientsecretcredential.construct}
*
* Sample: Construct a ClientSecretCredential behind a proxy
* {@codesnippet com.azure.identity.credential.clientsecretcredential.constructwithproxy}
*/
@Immutable
public class ClientSecretCredential implements TokenCredential {
/* The client secret value. */
private final String clientSecret;
private final IdentityClient identityClient;
/**
* Creates a ClientSecretCredential with the given identity client options.
*
* @param tenantId the tenant ID of the application
* @param clientId the client ID of the application
* @param clientSecret the secret value of the AAD application.
* @param identityClientOptions the options for configuring the identity client
*/
ClientSecretCredential(String tenantId, String clientId, String clientSecret,
IdentityClientOptions identityClientOptions) {
Objects.requireNonNull(clientSecret, "'clientSecret' cannot be null.");
Objects.requireNonNull(identityClientOptions, "'identityClientOptions' cannot be null.");
identityClient = new IdentityClientBuilder()
.tenantId(tenantId)
.clientId(clientId)
.identityClientOptions(identityClientOptions)
.build();
this.clientSecret = clientSecret;
}
@Override
public Mono getToken(TokenRequest request) {
return identityClient.authenticateWithClientSecret(clientSecret, request);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy