Skip to content

Commit 1f536ba

Browse files
authored
Initial commit (Azure#46759)
1 parent f25b742 commit 1f536ba

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ public async Task SharedKeyAuthAsync()
7575
// Create a SharedKeyCredential that we can use to authenticate
7676
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
7777

78-
// Create a client that can authenticate with a connection string
78+
// Create a client that can authenticate with a SharedKeyCredential
7979
ShareServiceClient service = new ShareServiceClient(serviceUri, credential);
8080

8181
// Make a service request to verify we've successfully authenticated
8282
await service.GetPropertiesAsync();
8383
}
8484

8585
/// <summary>
86-
/// Use a shared access signature to acces a Storage Account.
86+
/// Use a shared access signature to access a Storage Account.
8787
///
8888
/// A shared access signature (SAS) is a URI that grants restricted
8989
/// access rights to Azure Storage resources. You can provide a shared
@@ -133,5 +133,26 @@ public async Task SharedAccessSignatureAuthAsync()
133133
async () => await service.CreateShareAsync(Randomize("sample-share")));
134134
Assert.AreEqual(403, ex.Status);
135135
}
136+
137+
/// <summary>
138+
/// Use a TokenCredential to access a Storage Account.
139+
///
140+
/// TokenCredential represents credentials used to acquire
141+
/// OAuth 2.0 access tokens for authenticating requests to Azure services.
142+
/// </summary>
143+
[Test]
144+
public async Task TokenCredentialAuthAsync()
145+
{
146+
// Create a TokenCredential that we can use to authenticate
147+
TokenCredential credential = new DefaultAzureCredential();
148+
149+
// Create a client that can authenticate with a TokenCredential
150+
ShareServiceClient shareServiceClient = new ShareServiceClient(
151+
StorageAccountFileUri,
152+
credential);
153+
154+
// Make a service request to verify we've successfully authenticated
155+
await shareServiceClient.GetPropertiesAsync();
156+
}
136157
}
137158
}

0 commit comments

Comments
 (0)