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();
}
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();
}
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);
}
Aggregations