A shared access signature (SAS) enables you to grant limited access to containers and blobs in your storage account. When you create a SAS, you specify its constraints, including which Azure Storage resources a client is allowed to access, what permissions they have on those resources, and how long the SAS is valid.
Every SAS is signed with a key. You can sign a SAS in one of two ways:
This article shows how to use the storage account key to create an account SAS with the Azure Storage client library for .NET.
About the account SASAn account SAS is created at the level of the storage account. By creating an account SAS, you can:
Stored access policies aren't supported for an account SAS.
Create an account SASAn account SAS is signed with the account access key. You can use the StorageSharedKeyCredential class to create the credential that is used to sign the SAS.
The following code example shows how to create a new AccountSasBuilder object and call the ToSasQueryParameters method to get the account SAS token string.
public static async Task<string> CreateAccountSAS(StorageSharedKeyCredential sharedKey)
{
// Create a SAS token that's valid for one day
AccountSasBuilder sasBuilder = new AccountSasBuilder()
{
Services = AccountSasServices.Blobs | AccountSasServices.Queues,
ResourceTypes = AccountSasResourceTypes.Service,
ExpiresOn = DateTimeOffset.UtcNow.AddDays(1),
Protocol = SasProtocol.Https
};
sasBuilder.SetPermissions(AccountSasPermissions.Read |
AccountSasPermissions.Write);
// Use the key to get the SAS token
string sasToken = sasBuilder.ToSasQueryParameters(sharedKey).ToString();
return sasToken;
}
Use an account SAS from a client
To use the account SAS to access service-level APIs for the Blob service, create a BlobServiceClient object using the account SAS and the Blob Storage endpoint for your storage account.
string accountName = "<storage-account-name>";
string accountKey = "<storage-account-key>";
StorageSharedKeyCredential storageSharedKeyCredential =
new(accountName, accountKey);
// Create a BlobServiceClient object with the account SAS appended
string blobServiceURI = $"https://{accountName}.blob.core.windows.net";
string sasToken = await CreateAccountSAS(storageSharedKeyCredential);
BlobServiceClient blobServiceClientAccountSAS = new BlobServiceClient(
new Uri($"{blobServiceURI}?{sasToken}"));
Resources
To learn more about creating an account SAS using the Azure Blob Storage client library for .NET, see the following resources.
Client library resources See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4