-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
AzureIdentityExample.java
42 lines (33 loc) · 1.43 KB
/
AzureIdentityExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.storage.blob;
import com.azure.identity.DefaultAzureCredentialBuilder;
import java.util.Locale;
/**
* Creates default DefaultAzureCredential instance to use. This will use AZURE_CLIENT_ID,
* AZURE_CLIENT_SECRET, and AZURE_TENANT_ID environment variables to create a
* ClientSecretCredential.
*/
public class AzureIdentityExample {
/**
* Entry point into the Azure Identity example for Storage blobs.
* @param args Unused. Arguments to the program.
*/
public static void main(String[] args) {
String accountName = SampleHelper.getAccountName();
/*
* From the Azure portal, get your Storage account blob service URL endpoint.
* The URL typically looks like this:
*/
String endpoint = String.format(Locale.ROOT, "https://%s.blob.core.windows.net", accountName);
/*
* Create a storage client using the Azure Identity credentials.
*/
BlobServiceClient storageClient = new BlobServiceClientBuilder()
.endpoint(endpoint)
.credential(new DefaultAzureCredentialBuilder().build())
.buildClient();
System.out.println("Successfully setup client using the Azure Identity, please check the service version: "
+ storageClient.getProperties().getDefaultServiceVersion());
}
}