Skip to content

Commit 5b79944

Browse files
committed
Adding Azure AD login
1 parent daf8d5b commit 5b79944

4 files changed

+110
-11
lines changed

articles/storage/blobs/data-lake-storage-directory-file-acl-dotnet.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ using Azure;
4343

4444
## Connect to the account
4545

46-
To use the snippets in this article, you'll need to create a [DataLakeServiceClient](https://docs.microsoft.com/dotnet/api/azure.storage.files.datalake.datalakeserviceclient) instance that represents the storage account. The easiest way to get one is to use an account key.
46+
To use the snippets in this article, you'll need to create a [DataLakeServiceClient](https://docs.microsoft.com/dotnet/api/azure.storage.files.datalake.datalakeserviceclient) instance that represents the storage account.
47+
48+
### Connect by using an account key
49+
50+
This is the easiest way to connect to an account.
4751

4852
This example creates an instance of the [DataLakeServiceClient](https://docs.microsoft.com/dotnet/api/azure.storage.files.datalake.datalakeserviceclient?) by using an account key.
4953

@@ -61,6 +65,29 @@ public void GetDataLakeServiceClient(ref DataLakeServiceClient dataLakeServiceCl
6165
}
6266
```
6367

68+
### Connect by using Azure Active Directory (AD)
69+
70+
First, you'll have to configure a service principal and register your application with an Azure AD tenant. see [Acquire a token from Azure AD for authorizing requests from a client application](../common/storage-auth-aad-app.md).
71+
72+
Then, you can use the [Azure identity client library for .NET](https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/identity/Azure.Identity) to authenticate your application.
73+
74+
This example uses a client ID, a client secret, and a tenant ID but there are other ways to do this. See the [Azure identity client library for .NET](https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/identity/Azure.Identity) for more examples.
75+
76+
```cs
77+
public void GetDataLakeServiceClient(ref DataLakeServiceClient dataLakeServiceClient,
78+
String accountName, String clientID, string clientSecret, string tenantID)
79+
{
80+
81+
TokenCredential credential = new ClientSecretCredential(
82+
tenantID, clientID, clientSecret, new TokenCredentialOptions());
83+
84+
string dfsUri = "https://" + accountName + ".dfs.core.windows.net";
85+
86+
dataLakeServiceClient = new DataLakeServiceClient(new Uri(dfsUri), credential);
87+
}
88+
89+
```
90+
6491
## Create a file system
6592

6693
A file system acts as a container for your files. You can create one by calling the [DataLakeServiceClient.CreateFileSystem](https://docs.microsoft.com/dotnet/api/azure.storage.files.datalake.datalakeserviceclient.createfilesystemasync) method.

articles/storage/blobs/data-lake-storage-directory-file-acl-java.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,13 @@ import com.azure.storage.file.datalake.models.PathPermissions;
4949
import com.azure.storage.file.datalake.models.RolePermissions;
5050
```
5151

52-
If you plan to authenticate your client application by using Azure AD, then add these imports statements to your code file.
52+
## Connect to the account
5353

54-
```java
55-
import com.azure.identity.ClientSecretCredential;
56-
import com.azure.identity.ClientSecretCredentialBuilder;
57-
import com.azure.core.credential.TokenCredential;
58-
````
54+
To use the snippets in this article, you'll need to create a **DataLakeServiceClient** instance that represents the storage account.
5955

60-
## Connect to the account
56+
### Connect by using an account key
6157

62-
To use the snippets in this article, you'll need to create a **DataLakeServiceClient** instance that represents the storage account. The easiest way to get one is to use an account key.
58+
This is the easiest way to connect to an account.
6359

6460
This example creates an instance of the **DataLakeServiceClient** by using an account key.
6561

@@ -78,8 +74,33 @@ static public DataLakeServiceClient GetDataLakeServiceClient
7874

7975
return builder.buildClient();
8076
}
77+
```
78+
79+
### Connect by using Azure Active Directory (Azure AD)
80+
81+
First, you'll have to configure a service principal and register your application with an Azure AD tenant. see [Acquire a token from Azure AD for authorizing requests from a client application](../common/storage-auth-aad-app.md).
82+
83+
Then, you can use the [Azure identity client library for Java](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/identity/azure-identity) to authenticate your application.
8184

85+
This example uses a client ID, a client secret, and a tenant ID but there are other ways to do this. See the [Azure identity client library for Java](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/identity/azure-identity)) for more examples.
86+
87+
```java
88+
static public DataLakeServiceClient GetDataLakeServiceClient
89+
(String accountName, String clientId, String ClientSecret, String tenantID){
90+
91+
String endpoint = "https://" + accountName + ".dfs.core.windows.net";
92+
93+
ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
94+
.clientId(clientId)
95+
.clientSecret(ClientSecret)
96+
.tenantId(tenantID)
97+
.build();
98+
99+
DataLakeServiceClientBuilder builder = new DataLakeServiceClientBuilder();
100+
return builder.credential(clientSecretCredential).endpoint(endpoint).buildClient();
101+
}
82102
```
103+
83104
## Create a file system
84105

85106
A file system acts as a container for your files. You can create one by calling the **DataLakeServiceClient.createFileSystem** method.

articles/storage/blobs/data-lake-storage-directory-file-acl-javascript.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ const AzureStorageDataLake = require("@azure/storage-file-datalake");
4242

4343
## Connect to the account
4444

45-
To use the snippets in this article, you'll need to create a **DataLakeServiceClient** instance that represents the storage account. The easiest way to get one is to use an account key.
45+
To use the snippets in this article, you'll need to create a **DataLakeServiceClient** instance that represents the storage account.
46+
47+
### Connect by using an account key
48+
49+
This is the easiest way to connect to an account.
4650

4751
This example creates an instance of the **DataLakeServiceClient** by using an account key.
4852

@@ -63,6 +67,26 @@ function GetDataLakeServiceClient(accountName, accountKey) {
6367
> [!NOTE]
6468
> This method of authorization works only for Node.js applications. If you plan to run your code in a browser, you can authorize by using Azure Active Directory (AD). For guidance on how to do that, see the [Azure Storage File Data Lake client library for JavaScript](https://www.npmjs.com/package/@azure/storage-file-datalake) readme file.
6569
70+
### Connect by using Azure Active Directory (AD)
71+
72+
First, you'll have to configure a service principal and register your application with an Azure AD tenant. see [Acquire a token from Azure AD for authorizing requests from a client application](../common/storage-auth-aad-app.md).
73+
74+
Then, you can use the [Azure identity client library for JS](https://www.npmjs.com/package/@azure/identity) to authenticate your application.
75+
76+
This example uses a client ID, a client secret, and a tenant ID but there are other ways to do this. See the [Azure identity client library for JS](https://www.npmjs.com/package/@azure/identity) for more examples.
77+
78+
```javascript
79+
function GetDataLakeServiceClientAD(accountName, clientID, clientSecret, tenantID) {
80+
81+
const credential = new ClientSecretCredential(tenantID, clientID, clientSecret);
82+
83+
const datalakeServiceClient = new DataLakeServiceClient(
84+
`https://${accountName}.dfs.core.windows.net`, credential);
85+
86+
return datalakeServiceClient;
87+
}
88+
```
89+
6690
## Create a file system
6791

6892
A file system acts as a container for your files. You can create one by getting a **FileSystemClient** instance, and then calling the **FileSystemClient.Create** method.

articles/storage/blobs/data-lake-storage-directory-file-acl-python.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ from azure.storage.filedatalake._models import ContentSettings
4444

4545
## Connect to the account
4646

47-
To use the snippets in this article, you'll need to create a **DataLakeServiceClient** instance that represents the storage account. The easiest way to get one is to use an account key.
47+
To use the snippets in this article, you'll need to create a **DataLakeServiceClient** instance that represents the storage account.
48+
49+
### Connect by using an account key
50+
51+
This is the easiest way to connect to an account.
4852

4953
This example uses an account key to create a **DataLakeServiceClient** instance that represents the storage account.
5054

@@ -63,6 +67,29 @@ except Exception as e:
6367

6468
- Replace the `storage_account_key` placeholder value with your storage account access key.
6569

70+
### Connect by using Azure Active Directory (AD)
71+
72+
First, you'll have to configure a service principal and register your application with an Azure AD tenant. see [Acquire a token from Azure AD for authorizing requests from a client application](../common/storage-auth-aad-app.md).
73+
74+
Then, you can use the [Azure identity client library for Python](https://pypi.org/project/azure-identity/) to authenticate your application.
75+
76+
This example uses a client ID, a client secret, and a tenant ID but there are other ways to do this. See the [Azure identity client library for Python](https://pypi.org/project/azure-identity/) for more examples.
77+
78+
```python
79+
def initialize_storage_account_ad(storage_account_name, client_id, client_secret, tenant_id):
80+
81+
try:
82+
global service_client
83+
84+
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
85+
86+
service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format(
87+
"https", storage_account_name), credential=credential)
88+
89+
except Exception as e:
90+
print(e)
91+
```
92+
6693
## Create a file system
6794

6895
A file system acts as a container for your files. You can create one by calling the **FileSystemDataLakeServiceClient.create_file_system** method.

0 commit comments

Comments
 (0)