Search in sources :

Example 1 with TokenCredential

use of com.azure.core.credential.TokenCredential in project samza by apache.

the class AzureBlobClientBuilder method getBlobServiceAsyncClient.

/**
 * method creates BlobServiceAsyncClient using the configs provided earlier.
 * if the authentication method is set to {@link TokenCredential} then a {@link com.azure.identity.ClientSecretCredential}
 * is created and used for the Blob client. Else authentication is done via account name and key using the
 * {@link StorageSharedKeyCredential}.
 * The config used to determine which authentication is systems.%s.azureblob.useTokenCredentialAuthentication = true
 * for using TokenCredential.
 * @return BlobServiceAsyncClient
 */
public BlobServiceAsyncClient getBlobServiceAsyncClient() {
    BlobServiceClientBuilder blobServiceClientBuilder = getBlobServiceClientBuilder();
    if (azureBlobConfig.getUseTokenCredentialAuthentication(systemName)) {
        // Use your Azure Blob Storage account's name and client details to create a token credential object to access your account.
        TokenCredential tokenCredential = getTokenCredential();
        return blobServiceClientBuilder.credential(tokenCredential).buildAsyncClient();
    }
    // Use your Azure Blob Storage account's name and key to create a credential object to access your account.
    StorageSharedKeyCredential storageSharedKeyCredential = getStorageSharedKeyCredential();
    return blobServiceClientBuilder.credential(storageSharedKeyCredential).buildAsyncClient();
}
Also used : BlobServiceClientBuilder(com.azure.storage.blob.BlobServiceClientBuilder) StorageSharedKeyCredential(com.azure.storage.common.StorageSharedKeyCredential) TokenCredential(com.azure.core.credential.TokenCredential)

Example 2 with TokenCredential

use of com.azure.core.credential.TokenCredential in project azure-iot-sdk-java by Azure.

the class Tools method buildDeviceMethodClientWithTokenCredential.

public static com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod buildDeviceMethodClientWithTokenCredential() {
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
    TokenCredential tokenCredential = buildTokenCredentialFromEnvironment();
    DeviceMethodClientOptions options = DeviceMethodClientOptions.builder().build();
    return new com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod(iotHubConnectionStringObj.getHostName(), tokenCredential, options);
}
Also used : DeviceMethodClientOptions(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethodClientOptions) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) TokenCredential(com.azure.core.credential.TokenCredential)

Example 3 with TokenCredential

use of com.azure.core.credential.TokenCredential in project azure-iot-sdk-java by Azure.

the class Tools method buildDigitalTwinClientWithTokenCredential.

public static DigitalTwinClient buildDigitalTwinClientWithTokenCredential() {
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
    TokenCredential tokenCredential = buildTokenCredentialFromEnvironment();
    DigitalTwinClientOptions options = DigitalTwinClientOptions.builder().build();
    return new DigitalTwinClient(iotHubConnectionStringObj.getHostName(), tokenCredential, options);
}
Also used : DigitalTwinClientOptions(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) TokenCredential(com.azure.core.credential.TokenCredential) DigitalTwinClient(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClient)

Example 4 with TokenCredential

use of com.azure.core.credential.TokenCredential in project azure-iot-sdk-java by Azure.

the class Tools method buildDeviceTwinClientWithTokenCredential.

public static DeviceTwin buildDeviceTwinClientWithTokenCredential() {
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
    TokenCredential tokenCredential = buildTokenCredentialFromEnvironment();
    DeviceTwinClientOptions options = DeviceTwinClientOptions.builder().build();
    return new DeviceTwin(iotHubConnectionStringObj.getHostName(), tokenCredential, options);
}
Also used : DeviceTwinClientOptions(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) TokenCredential(com.azure.core.credential.TokenCredential) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)

Example 5 with TokenCredential

use of com.azure.core.credential.TokenCredential in project azure-iot-sdk-java by Azure.

the class Tools method buildServiceClientWithTokenCredential.

public static ServiceClient buildServiceClientWithTokenCredential(IotHubServiceClientProtocol protocol) {
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
    TokenCredential tokenCredential = buildTokenCredentialFromEnvironment();
    return new ServiceClient(iotHubConnectionStringObj.getHostName(), tokenCredential, protocol);
}
Also used : ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) TokenCredential(com.azure.core.credential.TokenCredential)

Aggregations

TokenCredential (com.azure.core.credential.TokenCredential)6 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)4 ClientSecretCredentialBuilder (com.azure.identity.ClientSecretCredentialBuilder)1 BlobServiceClientBuilder (com.azure.storage.blob.BlobServiceClientBuilder)1 StorageSharedKeyCredential (com.azure.storage.common.StorageSharedKeyCredential)1 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)1 DeviceMethodClientOptions (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethodClientOptions)1 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)1 DeviceTwinClientOptions (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions)1 DigitalTwinClient (com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClient)1 DigitalTwinClientOptions (com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions)1