Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] Added samples of auth with TokenCredentials to Azure.Storage.Files.Shares #46759

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions sdk/storage/Azure.Storage.Files.Shares/samples/Sample02_Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ 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
await service.GetPropertiesAsync();
}

/// <summary>
/// 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
Expand Down Expand Up @@ -133,5 +133,26 @@ public async Task SharedAccessSignatureAuthAsync()
async () => await service.CreateShareAsync(Randomize("sample-share")));
Assert.AreEqual(403, ex.Status);
}

/// <summary>
/// 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.
/// </summary>
[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();
}
}
}