I've combed through at least a dozen different versions of this problem but none of them have so far produced an answer to the one I'm having. I'm attempting to develop a proof-of-concept for retrieving an image from Azure BLOB storage using Azurite and a service SAS with a corresponding storage account key. I'm using the well-known storage account credentials for Azurite as indicated here. There appear to be innumerable ways to do this kind of thing in C# but I opted to loosely follow this example and ended up with something like this:
public Uri GetSharedKeySasUrl()
{
BlobServiceClient serviceClient = new BlobServiceClient(
new Uri("http://127.0.0.1:10000/devstoreaccount1/"),
new Azure.Storage.StorageSharedKeyCredential(
"devstoreaccount1",
"Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
)
);
var blobContainer = serviceClient.GetBlobContainerClient("images");
var blobClient = blobContainer.GetBlobClient("00000-pano.jpg");
BlobSasBuilder sasBuilder = new BlobSasBuilder()
{
BlobContainerName = "images",
BlobName = "00000-pano.jpg",
Resource = "b",
StartsOn = DateTimeOffset.UtcNow,
ExpiresOn = DateTimeOffset.UtcNow.AddHours(1)
};
sasBuilder.SetPermissions(BlobSasPermissions.Read);
Uri sasUri = blobClient.GenerateSasUri(sasBuilder);
Debug.WriteLine("SAS URI for blob is: {0}", sasUri);
return sasUri;
}
This produces a URL that looks as though it should work just fine, but whenever I paste it into a browser and attempt to access it I consistently get the following:
<Error>
<Code>AuthorizationFailure</Code>
<Message>Server failed to authenticate the request. Make sure the value of the Authorization header is formed correctly including the signature. RequestId:551902dd-ecb8-4736-9cf1-32406d98c02f Time:2022-04-11T20:18:06.368Z</Message>
</Error>
Conversely, if I generate a SAS signature through the Microsoft Azure Storage Explorer, that URL works perfectly. If I compare this URL to the URL this method generates, both seem to be perfectly well-formatted - I can't see anything that would suggest mine is malformed.
Generated by the method:
http://127.0.0.1:10000/devstoreaccount1/images/00000-pano.jpg?sv=2021-04-10&st=2022-04-11T20%3A17%3A59Z&se=2022-04-11T21%3A17%3A59Z&sr=b&sp=r&sig=bUHI2562NmvvtflOqT5kr0E%2BnZv7Q12PlR%2FGNPmEhL8%3D
Generated in Storage Explorer:
http://127.0.0.1:10000/devstoreaccount1/images/00000-pano.jpg?sv=2018-03-28&st=2022-04-11T20%3A06%3A47Z&se=2022-04-12T20%3A06%3A47Z&sr=b&sp=r&sig=V6N7uWDGgoVx8wirM%2FP1ou2kbg05PB4D%2BG8YQdvS5RU%3D
The only notable difference seems to be the version of the service each one is using - the explorer uses 2018-03-28 while the method uses 2021-04-10. I've tried assigning the version in the BlobSasBuilder but it just gets ignored, which is consistent with Microsoft's own remarks about the property being deprecated and the class always using the latest supported version of the service regardless of what you specify here. I still don't think that explains the issue, though.
Any ideas? Thanks in advance for the help.
EDIT
I remain hopelessly stuck on this. I've made numerous attempts to reformulate the code I'm using to construct the SAS URI in hopes that something might work. Not a single one has worked so far. The methods I've tried:
- Using the
BlobUriBuilder,SasBuilderandStorageSharedKeyCredentialto generate the URI - Using the
BlobServiceClientwith aStorageSharedKeyCredentialto derive theBlobContainerClientand in turn theBlobClient, and then theSasBuilderto generate the URI - Same as above using a connection string with the
BlobServiceClientin place of aStorageSharedKeyCredential - Same as above using
"UseDevelopmentStorage=true"as the connection string with theBlobServiceClient - Signing the string manually using
HMACSHA256and aNameValueCollectionto construct the query parameters
I've also experimented with running Azurite using different startup options, including azurite --loose and azurite --skipApiVersionCheck. Neither one makes any difference.
Other things I've tried:
- Updating the version of Azurite I'm using
- Running Azurite from within Visual Studio as a service dependency
I simply can't understand why this would be such an insurmountable problem. Please help.






