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(); + } } }