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
Azure Active Directory (Azure AD) provides the most secure connection by managing the connection identity ([**managed identity**](../../active-directory/managed-identities-azure-resources/overview.md)). This **passwordless** functionality allows you to develop an application that doesn't require any secrets (keys or connection strings) stored in the code.
75
74
76
-
// optional but recommended - connect with managed identity (Azure AD)
To connect to Azure without passwords, you need to set up an Azure identity or use an existing identity. Once the identity is set up, make sure to assign the appropriate roles to the identity.
79
78
80
-
## Connect with Azure AD
79
+
To authorize passwordless access with Azure AD, you'll need to use an Azure credential. Which type of credential you need depends on where your application runs. Use this table as a guide.
81
80
82
-
Azure Active Directory (Azure AD) provides the most secure connection by managing the connection identity ([**managed identity**](../../active-directory/managed-identities-azure-resources/overview.md)). This functionality allows you to develop code that doesn't require any secrets (keys or connection strings) stored in the code or environment. Managed identity requires [**setup**](assign-azure-role-data-access.md?tabs=portal) forany identities such as developer (personal) or cloud (hosting) environments. You need to complete the setup before using the codein this section.
81
+
|Environment|Method|
82
+
|--|--|
83
+
|Developer environment|[Visual Studio Code](/azure/developer/javascript/sdk/authentication/local-development-environment-developer-account?tabs=azure-portal%2Csign-in-vscode)|
After you complete the setup, your Storage resource needs to have one or more of the following roles assigned to the identity resource you plan to connect with:
88
+
### Set up storage account roles
85
89
90
+
Your storage resource needs to have one or more of the following [Azure RBAC](/azure/role-based-access-control/built-in-roles) roles assigned to the identity resource you plan to connect with. [Setup the Azure Storage roles](assign-azure-role-data-access.md?tabs=portal) for each identity you created in the previous step: Azure cloud, local development, on-premises.
91
+
92
+
After you complete the setup, each identity needs at least one of the appropriate roles:
93
+
86
94
* A [data access](../common/authorize-data-access.md) role - such as:
87
95
* **Storage Blob Data Reader**
88
96
* **Storage Blob Data Contributor**
89
97
* A [resource](../common/authorization-resource-provider.md) role - such as:
90
98
* **Reader**
91
99
* **Contributor**
92
100
93
-
To authorize with Azure AD, you'll need to use an Azure credential. Which type of credential you need depends on where your application runs. Use this table as a guide.
94
-
95
-
| Where the application runs | Security principal | Guidance |
96
-
|--|--|---|
97
-
| Local machine (developing and testing) | User identity or service principal | [Use the Azure Identity library to get an access token for authorization](../common/identity-library-acquire-token.md) |
98
-
| Azure | Managed identity | [Authorize access to blob data with managed identities for Azure resources](authorize-managed-identity.md) |
99
-
| Servers or clients outside of Azure | Service principal | [Authorize access to blob or queue data from a native or web application](../common/storage-auth-aad-app.md?toc=/azure/storage/blobs/toc.json) |
100
-
101
-
Create a [DefaultAzureCredential](/javascript/api/overview/azure/identity-readme#defaultazurecredential) instance. Use that object to create a [BlobServiceClient](/javascript/api/@azure/storage-blob/blobserviceclient).
if (!accountName) throw Error('Azure Storage accountName not found');
110
101
111
-
const blobServiceClient = new BlobServiceClient(
112
-
`https://${accountName}.blob.core.windows.net`,
113
-
new DefaultAzureCredential()
114
-
);
102
+
### Connect with passwordless authentication to Azure
115
103
116
-
async function main(){
104
+
Once your Azure storage account identity roles and your local environment are set up, create a JavaScript file which includes the [``@azure/identity``](https://www.npmjs.com/package/@azure/identity) package. Using the `DefaultAzureCredential` class provided by the Azure.Identity client library is the recommended approach for implementing passwordless connections to Azure services in your code, including Blob Storage.
Create a [DefaultAzureCredential](/javascript/api/overview/azure/identity-readme#defaultazurecredential) instance. Use that object to create a [BlobServiceClient](/javascript/api/@azure/storage-blob/blobserviceclient).
The `dotenv` package is used to read your storage account name from a `.env` file. This file should not be checked into source control. If you use a local service principal as part of your DefaultAzureCredential set up, any security information for that credential will also go into the `.env` file.
128
111
129
112
If you plan to deploy the application to servers and clients that run outside of Azure, you can obtain an OAuth token by using other classes in the [Azure Identity client library for JavaScript](/javascript/api/overview/azure/identity-readme) which derive from the [TokenCredential](/javascript/api/@azure/core-auth/tokencredential) class.
130
113
131
114
## Connect with an account name and key
132
115
133
116
Create a [StorageSharedKeyCredential](/javascript/api/@azure/storage-blob/storagesharedkeycredential) by using the storage account name and account key. Then use the StorageSharedKeyCredential to initialize a [BlobServiceClient](/javascript/api/@azure/storage-blob/blobserviceclient).
The `dotenv` package is used to read your storage account name and key from a `.env` file. This file should not be checked into source control.
160
121
161
122
For information about how to obtain account keys and best practice guidelines for properly managing and safeguarding your keys, see [Manage storage account access keys](../common/storage-account-keys-manage.md).
162
123
163
124
## Connect with a connection string
164
125
165
126
Create a [BlobServiceClient](/javascript/api/@azure/storage-blob/blobserviceclient) by using a connection string.
The `dotenv` package is used to read your storage account connection string from a `.env` file. This file should not be checked into source control.
185
131
186
132
For information about how to obtain account keys and best practice guidelines for properly managing and safeguarding your keys, see [Manage storage account access keys](../common/storage-account-keys-manage.md).
187
133
188
-
## Object Authorization with a SAS token
134
+
## Connect with a SAS token
189
135
190
136
Create a Uri to your resource by using the blob service endpoint and SAS token. Then, create a [BlobServiceClient](/javascript/api/@azure/storage-blob/blobserviceclient) with the Uri.
The `dotenv` package is used to read your storage account name and sas token from a `.env` file. This file should not be checked into source control.
217
141
218
142
To generate and manage SAS tokens, see any of these articles:
219
143
220
144
- [Grant limited access to Azure Storage resources using shared access signatures (SAS)](../common/storage-sas-overview.md?toc=/azure/storage/blobs/toc.json)
221
145
222
146
- [Create a service SAS for a container or blob](sas-service-create.md)
223
147
224
-
225
-
226
-
227
148
## Connect anonymously
228
149
229
150
If you explicitly enable anonymous access, then you can connect to Blob Storage without authorization for your request. You can create a new BlobServiceClient object for anonymous access by providing the Blob storage endpoint for the account. This requires you to know the account and container names. To learn how to enable anonymous access, see [Configure anonymous public read access for containers and blobs](anonymous-read-access-configure.md).
The `dotenv` package is used to read your storage account name from a `.env` file. This file should not be checked into source control.
260
155
261
156
Each type of resource is represented by one or more associated JavaScript clients:
262
157
@@ -271,10 +166,12 @@ The following guides show you how to use each of these clients to build your app
271
166
| Guide | Description |
272
167
|--|---|
273
168
| [Create a container](storage-blob-container-create-javascript.md) | Create containers. |
169
+
| [Get container's URL](storage-blob-get-url-javascript.md) | Get URL of container. |
274
170
| [Delete and restore containers](storage-blob-container-delete-javascript.md) | Delete containers, and if soft-delete is enabled, restore deleted containers. |
275
171
| [List containers](storage-blob-containers-list-javascript.md) | List containers in an account and the various options available to customize a listing. |
276
172
| [Manage properties and metadata](storage-blob-container-properties-metadata-javascript.md) | Get and set properties and metadata for containers. |
277
173
| [Upload blobs](storage-blob-upload-javascript.md) | Learn how to upload blobs by using strings, streams, file paths, and other methods. |
174
+
| [Get blob's URL](storage-blob-get-url-javascript.md) | Get URL of blob. |
278
175
| [Download blobs](storage-blob-download-javascript.md) | Download blobs by using strings, streams, and file paths. |
279
176
| [Copy blobs](storage-blob-copy-javascript.md) | Copy a blob from one account to another account. |
280
177
| [List blobs](storage-blobs-list-javascript.md) | List blobs in different ways. |
0 commit comments