Skip to content

Commit df0e382

Browse files
Merge pull request #295380 from pauljewellmsft/files-sfi
Update sample to remove connection string auth
2 parents e300b2c + 19bba71 commit df0e382

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

articles/storage/files/authorize-oauth-rest.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Authorize admin-level read and write access to Azure file shares an
44
author: khdownie
55
ms.service: azure-file-storage
66
ms.topic: conceptual
7-
ms.date: 05/08/2024
7+
ms.date: 02/26/2025
88
ms.author: kendownie
99
ms.custom: devx-track-azurepowershell
1010
---
@@ -88,7 +88,7 @@ An advantage of the Azure Identity client library is that it enables you to use
8888

8989
The access token returned by the Azure Identity client library is encapsulated in a token credential. You can then use the token credential to get a service client object to use in performing authorized operations against the Azure Files service.
9090

91-
Here's some sample code:
91+
The following code example shows how to authorize a client object using Microsoft Entra ID and perform operations at the directory and file level. This example assumes that the file share already exists.
9292

9393
```aspx-csharp
9494
using Azure.Core;
@@ -105,35 +105,30 @@ namespace FilesOAuthSample
105105
string tenantId = "";
106106
string appId = "";
107107
string appSecret = "";
108-
string aadEndpoint = "";
109-
string accountUri = "";
110-
string connectionString = "";
108+
string entraEndpoint = "";
109+
string accountUri = "https://<storage-account-name>.file.core.windows.net/";
111110
string shareName = "test-share";
112-
string directoryName = "testDirectory";
113-
string fileName = "testFile";
114-
115-
ShareClient sharedKeyShareClient = new ShareClient(connectionString, shareName);
116-
await sharedKeyShareClient.CreateIfNotExistsAsync();
111+
string directoryName = "test-directory";
112+
string fileName = "test-file";
117113
118114
TokenCredential tokenCredential = new ClientSecretCredential(
119115
tenantId,
120116
appId,
121117
appSecret,
122118
new TokenCredentialOptions()
123119
{
124-
AuthorityHost = new Uri(aadEndpoint)
120+
AuthorityHost = new Uri(entraEndpoint)
125121
});
126122
127-
ShareClientOptions clientOptions = new ShareClientOptions(ShareClientOptions.ServiceVersion.V2023_05_03);
128-
129-
// Set Allow Trailing Dot and Source Allow Trailing Dot.
123+
// Set client options
124+
ShareClientOptions clientOptions = new ShareClientOptions();
130125
clientOptions.AllowTrailingDot = true;
131126
clientOptions.AllowSourceTrailingDot = true;
132127
133128
// x-ms-file-intent=backup will automatically be applied to all APIs
134-
// where it is required in derived clients.
135-
129+
// where it is required in derived clients
136130
clientOptions.ShareTokenIntent = ShareTokenIntent.Backup;
131+
137132
ShareServiceClient shareServiceClient = new ShareServiceClient(
138133
new Uri(accountUri),
139134
tokenCredential,
@@ -146,7 +141,6 @@ namespace FilesOAuthSample
146141
ShareFileClient fileClient = directoryClient.GetFileClient(fileName);
147142
await fileClient.CreateAsync(maxSize: 1024);
148143
await fileClient.GetPropertiesAsync();
149-
await sharedKeyShareClient.DeleteIfExistsAsync();
150144
}
151145
}
152146
}

0 commit comments

Comments
 (0)