All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.identity.credential.ClientSecretCredential Maven / Gradle / Ivy

There is a newer version: 1.16.0-beta.1
Show newest version
// 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