You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This article shows how to use Azure Active Directory (Azure AD) credentials to create a user delegation SAS for a container, directory, or blob with the Blob Storage client library for .NET version 12.
21
+
This article shows how to use Azure Active Directory (Azure AD) credentials to create a user delegation SAS for a container, directory, or blob with the Blob Storage client library for .NET.
When an Azure AD security principal attempts to access blob data, that security principal must have permissions to the resource. Whether the security principal is a managed identity in Azure or an Azure AD user account running code in the development environment, the security principal must be assigned an Azure role that grants access to blob data. For information about assigning permissions via Azure RBAC, see [Assign an Azure role for access to blob data](assign-azure-role-data-access.md).
28
28
29
+
## Set up your project
30
+
31
+
To work with the code examples in this article, follow these steps to set up your project.
32
+
33
+
### Install packages
34
+
35
+
For the [blob](#get-a-user-delegation-sas-for-a-blob) and [container](#get-a-user-delegation-sas-for-a-container) code examples, add the following packages:
36
+
37
+
### [.NET CLI](#tab/packages-dotnetcli)
38
+
39
+
```dotnetcli
40
+
dotnet add package Azure.Identity
41
+
dotnet add package Azure.Storage.Blobs
42
+
```
43
+
44
+
### [PowerShell](#tab/packages-powershell)
45
+
46
+
```powershell
47
+
Install-Package Azure.Identity
48
+
Install-Package Azure.Storage.Blobs
49
+
```
50
+
---
51
+
52
+
For the [directory](#get-a-user-delegation-sas-for-a-directory) code examples, add the following packages:
53
+
54
+
### [.NET CLI](#tab/packages-dotnetcli)
55
+
56
+
```dotnetcli
57
+
dotnet add package Azure.Identity
58
+
dotnet add package Azure.Storage.Files.DataLake
59
+
```
60
+
61
+
### [PowerShell](#tab/packages-powershell)
62
+
63
+
```powershell
64
+
Install-Package Azure.Identity
65
+
Install-Package Azure.Storage.Files.DataLake
66
+
```
67
+
---
68
+
69
+
### Set up the app code
70
+
71
+
For the [blob](#get-a-user-delegation-sas-for-a-blob) and [container](#get-a-user-delegation-sas-for-a-container) code examples, add the following `using` directives:
72
+
73
+
```csharp
74
+
usingAzure;
75
+
usingAzure.Identity;
76
+
usingAzure.Storage.Blobs;
77
+
usingAzure.Storage.Blobs.Models;
78
+
usingAzure.Storage.Blobs.Specialized;
79
+
usingAzure.Storage.Sas;
80
+
```
81
+
82
+
For the [directory](#get-a-user-delegation-sas-for-a-directory) code example, add the following `using` directives:
83
+
84
+
```csharp
85
+
usingAzure;
86
+
usingAzure.Identity;
87
+
usingAzure.Storage.Files.DataLake;
88
+
usingAzure.Storage.Files.DataLake.Models;
89
+
usingAzure.Storage.Sas;
90
+
```
91
+
29
92
## Get an authenticated token credential
30
93
31
94
To get a token credential that your code can use to authorize requests to Blob Storage, create an instance of the [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) class. For more information about using the DefaultAzureCredential class to authorize a managed identity to access Blob Storage, see [Azure Identity client library for .NET](/dotnet/api/overview/azure/identity-readme).
@@ -34,11 +97,11 @@ The following code snippet shows how to get the authenticated token credential a
34
97
35
98
```csharp
36
99
// Construct the blob endpoint from the account name.
To learn more about authorizing access to Blob Storage from your applications with the .NET SDK, see [How to authenticate .NET applications with Azure services](/dotnet/azure/sdk/authentication).
@@ -57,19 +120,19 @@ Use one of the following methods to request the user delegation key:
57
120
The following code snippet gets the user delegation key and writes out its properties:
58
121
59
122
```csharp
60
-
// Get a user delegation key for the Blob service that's valid for seven days.
61
-
// You can use the key to generate any number of shared access signatures over the lifetime of the key.
123
+
// Get a user delegation key for the Blob service that's valid for seven days
124
+
// You can use the key to generate any number of shared access signatures over the lifetime of the key
0 commit comments