Search in sources :

Example 1 with ClientSecretCredentialBuilder

use of com.azure.identity.ClientSecretCredentialBuilder in project ambry by linkedin.

the class AzureUtils method getClientSecretCredential.

/**
 * @param azureCloudConfig the {@link AzureCloudConfig} to source credential configs from.
 * @return the {@link ClientSecretCredential}.
 */
static ClientSecretCredential getClientSecretCredential(AzureCloudConfig azureCloudConfig) {
    ClientSecretCredentialBuilder builder = new ClientSecretCredentialBuilder().tenantId(azureCloudConfig.azureIdentityTenantId).clientId(azureCloudConfig.azureIdentityClientId).clientSecret(azureCloudConfig.azureIdentitySecret);
    if (!azureCloudConfig.azureIdentityProxyHost.isEmpty()) {
        logger.info("Using proxy for ClientSecretCredential: {}:{}", azureCloudConfig.azureIdentityProxyHost, azureCloudConfig.azureIdentityProxyPort);
        ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress(azureCloudConfig.azureIdentityProxyHost, azureCloudConfig.azureIdentityProxyPort));
        HttpClient httpClient = new NettyAsyncHttpClientBuilder().proxy(proxyOptions).build();
        builder.httpClient(httpClient);
    }
    return builder.build();
}
Also used : ProxyOptions(com.azure.core.http.ProxyOptions) ClientSecretCredentialBuilder(com.azure.identity.ClientSecretCredentialBuilder) InetSocketAddress(java.net.InetSocketAddress) HttpClient(com.azure.core.http.HttpClient) NettyAsyncHttpClientBuilder(com.azure.core.http.netty.NettyAsyncHttpClientBuilder)

Example 2 with ClientSecretCredentialBuilder

use of com.azure.identity.ClientSecretCredentialBuilder in project azure-iot-sdk-java by Azure.

the class Tools method buildTokenCredentialFromEnvironment.

public static TokenCredential buildTokenCredentialFromEnvironment() {
    String tenantId = retrieveEnvironmentVariableValue(MSFT_TENANT_ID_ENV_VAR_NAME);
    String clientId = retrieveEnvironmentVariableValue(IOTHUB_CLIENT_ID_ENV_VAR_NAME);
    String clientSecret = retrieveEnvironmentVariableValue(IOTHUB_CLIENT_SECRET_ENV_VAR_NAME);
    Objects.requireNonNull(tenantId, MSFT_TENANT_ID_ENV_VAR_NAME + " not found in environment variables");
    Objects.requireNonNull(clientId, IOTHUB_CLIENT_ID_ENV_VAR_NAME + " not found in environment variables");
    Objects.requireNonNull(clientSecret, IOTHUB_CLIENT_SECRET_ENV_VAR_NAME + " not found in environment variables");
    return new ClientSecretCredentialBuilder().clientSecret(clientSecret).clientId(clientId).tenantId(tenantId).build();
}
Also used : ClientSecretCredentialBuilder(com.azure.identity.ClientSecretCredentialBuilder) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString)

Example 3 with ClientSecretCredentialBuilder

use of com.azure.identity.ClientSecretCredentialBuilder in project azure-iot-sdk-java by Azure.

the class RoleBasedAuthenticationSample method main.

public static void main(String[] args) {
    SamplesArguments parsedArguments = new SamplesArguments(args);
    // Credentials can be built from types from the Azure Identity library like ClientSecretCredential.
    // The Azure Identity library also defines other implementations of the TokenCredential interface such as
    // DefaultAzureCredential, InteractiveBrowserCredential, and many others.
    TokenCredential credential = new ClientSecretCredentialBuilder().tenantId(parsedArguments.getTenantId()).clientId(parsedArguments.getClientId()).clientSecret(parsedArguments.getClientSecret()).build();
    // "my-azure-iot-hub.azure-devices.net" for example
    String iotHubHostName = parsedArguments.getIotHubHostName();
    String newDeviceId = runRegistryManagerSample(iotHubHostName, credential);
    runTwinClientSample(iotHubHostName, credential, newDeviceId);
    runServiceClientSample(iotHubHostName, credential, newDeviceId);
    runJobClientSample(iotHubHostName, credential);
    runDeviceMethodClientSample(iotHubHostName, credential, newDeviceId);
}
Also used : ClientSecretCredentialBuilder(com.azure.identity.ClientSecretCredentialBuilder) TokenCredential(com.azure.core.credential.TokenCredential)

Aggregations

ClientSecretCredentialBuilder (com.azure.identity.ClientSecretCredentialBuilder)3 TokenCredential (com.azure.core.credential.TokenCredential)1 HttpClient (com.azure.core.http.HttpClient)1 ProxyOptions (com.azure.core.http.ProxyOptions)1 NettyAsyncHttpClientBuilder (com.azure.core.http.netty.NettyAsyncHttpClientBuilder)1 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 InetSocketAddress (java.net.InetSocketAddress)1