Skip to content

Commit 8a3fa5d

Browse files
authored
[Storage] [Tests] Fix OAuth Storage Samples (#45083)
* Fix storage samples * Update snippets
1 parent fb8b11b commit 8a3fa5d

File tree

7 files changed

+12
-47
lines changed

7 files changed

+12
-47
lines changed

sdk/storage/Azure.Storage.Blobs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ We fully support both synchronous and asynchronous APIs.
149149
// Get a temporary path on disk where we can download the file
150150
string downloadPath = "hello.jpg";
151151

152-
// Download the public blob at https://aka.ms/bloburl
153-
await new BlobClient(new Uri("https://aka.ms/bloburl")).DownloadToAsync(downloadPath);
152+
// Download the public MacBeth copy at https://www.gutenberg.org/cache/epub/1533/pg1533.txt
153+
await new BlobClient(new Uri("https://www.gutenberg.org/cache/epub/1533/pg1533.txt")).DownloadToAsync(downloadPath);
154154
```
155155

156156
## Troubleshooting

sdk/storage/Azure.Storage.Blobs/samples/Sample01b_HelloWorldAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ public async Task DownloadImageAsync()
109109
// Get a temporary path on disk where we can download the file
110110
//@@ string downloadPath = "hello.jpg";
111111

112-
// Download the public blob at https://aka.ms/bloburl
113-
await new BlobClient(new Uri("https://aka.ms/bloburl")).DownloadToAsync(downloadPath);
112+
// Download the public MacBeth copy at https://www.gutenberg.org/cache/epub/1533/pg1533.txt
113+
await new BlobClient(new Uri("https://www.gutenberg.org/cache/epub/1533/pg1533.txt")).DownloadToAsync(downloadPath);
114114
#endregion
115115

116116
Assert.IsTrue(File.ReadAllBytes(downloadPath).Length > 0);
117-
File.Delete("hello.jpg");
117+
File.Delete(downloadPath);
118118
}
119119

120120
/// <summary>

sdk/storage/Azure.Storage.Blobs/samples/Sample02_Auth.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,7 @@ public async Task ActiveDirectoryAuthAsync()
192192
{
193193
// Create a token credential that can use our Azure Active
194194
// Directory application to authenticate with Azure Storage
195-
TokenCredential credential =
196-
new ClientSecretCredential(
197-
ActiveDirectoryTenantId,
198-
ActiveDirectoryApplicationId,
199-
ActiveDirectoryApplicationSecret,
200-
new TokenCredentialOptions() { AuthorityHost = ActiveDirectoryAuthEndpoint });
195+
TokenCredential credential = new DefaultAzureCredential();
201196

202197
// Create a client that can authenticate using our token credential
203198
BlobServiceClient service = new BlobServiceClient(ActiveDirectoryBlobUri, credential);

sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ public async Task ResourceConstructionDemonstration()
3838
try
3939
{
4040
{
41-
TokenCredential tokenCredential =
42-
new ClientSecretCredential(
43-
ActiveDirectoryTenantId,
44-
ActiveDirectoryApplicationId,
45-
ActiveDirectoryApplicationSecret,
46-
new TokenCredentialOptions() { AuthorityHost = ActiveDirectoryAuthEndpoint });
41+
TokenCredential tokenCredential = new DefaultAzureCredential();
4742

4843
TransferManager transferManager = new TransferManager();
4944

@@ -612,12 +607,7 @@ public async Task DownloadDirectory_EventHandler_ActiveDirectoryAuthAsync()
612607

613608
// Create a token credential that can use our Azure Active
614609
// Directory application to authenticate with Azure Storage
615-
TokenCredential credential =
616-
new ClientSecretCredential(
617-
ActiveDirectoryTenantId,
618-
ActiveDirectoryApplicationId,
619-
ActiveDirectoryApplicationSecret,
620-
new TokenCredentialOptions() { AuthorityHost = ActiveDirectoryAuthEndpoint });
610+
TokenCredential credential = new DefaultAzureCredential();
621611

622612
// Create a client that can authenticate using our token credential
623613
BlobServiceClient service = new BlobServiceClient(ActiveDirectoryBlobUri, credential);
@@ -882,12 +872,7 @@ public async Task PauseAndResumeAsync_ManagerId()
882872

883873
// Create a token credential that can use our Azure Active
884874
// Directory application to authenticate with Azure Storage
885-
TokenCredential tokenCredential =
886-
new ClientSecretCredential(
887-
ActiveDirectoryTenantId,
888-
ActiveDirectoryApplicationId,
889-
ActiveDirectoryApplicationSecret,
890-
new TokenCredentialOptions() { AuthorityHost = ActiveDirectoryAuthEndpoint });
875+
TokenCredential tokenCredential = new DefaultAzureCredential();
891876

892877
// Create transfer manager
893878
#region Snippet:SetupTransferManagerForResume

sdk/storage/Azure.Storage.DataMovement.Files.Shares/samples/Sample01b_HelloWorldAsync.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ public async Task ResourceConstructionDemonstration()
3737
try
3838
{
3939
{
40-
TokenCredential tokenCredential =
41-
new ClientSecretCredential(
42-
ActiveDirectoryTenantId,
43-
ActiveDirectoryApplicationId,
44-
ActiveDirectoryApplicationSecret,
45-
new TokenCredentialOptions() { AuthorityHost = ActiveDirectoryAuthEndpoint });
40+
TokenCredential tokenCredential = new DefaultAzureCredential();
4641

4742
TransferManager transferManager = new TransferManager();
4843

sdk/storage/Azure.Storage.Files.DataLake/samples/Sample02_Auth.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,7 @@ public async Task ActiveDirectoryAuthAsync()
182182
{
183183
// Create a token credential that can use our Azure Active
184184
// Directory application to authenticate with Azure Storage
185-
TokenCredential credential =
186-
new ClientSecretCredential(
187-
ActiveDirectoryTenantId,
188-
ActiveDirectoryApplicationId,
189-
ActiveDirectoryApplicationSecret,
190-
new TokenCredentialOptions() { AuthorityHost = ActiveDirectoryAuthEndpoint });
185+
TokenCredential credential = new DefaultAzureCredential();
191186

192187
// Create a client that can authenticate using our token credential
193188
DataLakeServiceClient service = new DataLakeServiceClient(ActiveDirectoryBlobUri, credential);

sdk/storage/Azure.Storage.Queues/samples/Sample02_Auth.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,7 @@ public async Task ActiveDirectoryAuthAsync()
155155
{
156156
// Create a token credential that can use our Azure Active
157157
// Directory application to authenticate with Azure Storage
158-
TokenCredential credential =
159-
new ClientSecretCredential(
160-
ActiveDirectoryTenantId,
161-
ActiveDirectoryApplicationId,
162-
ActiveDirectoryApplicationSecret,
163-
new TokenCredentialOptions() { AuthorityHost = ActiveDirectoryAuthEndpoint });
158+
TokenCredential credential = new DefaultAzureCredential();
164159

165160
// Create a client that can authenticate using our token credential
166161
QueueServiceClient service = new QueueServiceClient(ActiveDirectoryQueueUri, credential);

0 commit comments

Comments
 (0)