From 1d55a0e5cd57e1a1a450e7c118b6dccdaa94fce2 Mon Sep 17 00:00:00 2001 From: nickliu-msft Date: Tue, 22 Oct 2024 13:39:26 -0400 Subject: [PATCH] Initial commit --- .../samples/Sample02_Auth.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/sdk/storage/Azure.Storage.Files.Shares/samples/Sample02_Auth.cs b/sdk/storage/Azure.Storage.Files.Shares/samples/Sample02_Auth.cs index af485310f0981..d8e8ad7694635 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/samples/Sample02_Auth.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/samples/Sample02_Auth.cs @@ -75,7 +75,7 @@ public async Task SharedKeyAuthAsync() // Create a SharedKeyCredential that we can use to authenticate StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey); - // Create a client that can authenticate with a connection string + // Create a client that can authenticate with a SharedKeyCredential ShareServiceClient service = new ShareServiceClient(serviceUri, credential); // Make a service request to verify we've successfully authenticated @@ -83,7 +83,7 @@ public async Task SharedKeyAuthAsync() } /// - /// Use a shared access signature to acces a Storage Account. + /// Use a shared access signature to access a Storage Account. /// /// A shared access signature (SAS) is a URI that grants restricted /// access rights to Azure Storage resources. You can provide a shared @@ -133,5 +133,26 @@ public async Task SharedAccessSignatureAuthAsync() async () => await service.CreateShareAsync(Randomize("sample-share"))); Assert.AreEqual(403, ex.Status); } + + /// + /// Use a TokenCredential to access a Storage Account. + /// + /// TokenCredential represents credentials used to acquire + /// OAuth 2.0 access tokens for authenticating requests to Azure services. + /// + [Test] + public async Task TokenCredentialAuthAsync() + { + // Create a TokenCredential that we can use to authenticate + TokenCredential credential = new DefaultAzureCredential(); + + // Create a client that can authenticate with a TokenCredential + ShareServiceClient shareServiceClient = new ShareServiceClient( + StorageAccountFileUri, + credential); + + // Make a service request to verify we've successfully authenticated + await shareServiceClient.GetPropertiesAsync(); + } } }