I am attempting to access a blob storage account and simply list the contents of a container using a SAS token. I am generating an access policy (according to this doc) and referencing that access policy within my access token as well.
Unfortunately, when my code attempts to run the ListBlobsSegmented
function, I receive a 403 (Forbidden) error.
This is the code that attempts to get the listing of blobs:
string storageAccountName = "ringclone";
string containerName = "ringcentral-archives";
string authenticationKey = "?sv=2018-03-28&si=ringclone-access-policy&sr=c&sig=************************";
StorageCredentials creds;
CloudStorageAccount account;
CloudBlobClient blobClient;
CloudBlobContainer cloudBlobContainer;
creds = new StorageCredentials(authenticationKey);
account = new CloudStorageAccount(creds, storageAccountName, endpointSuffix: null, useHttps: true);
blobClient = account.CreateCloudBlobClient();
cloudBlobContainer = blobClient.GetContainerReference(containerName);
BlobContinuationToken blobContinuationToken = null;
var containerSegment = blobClient.ListBlobsSegmented("", blobContinuationToken); // 403 error;
And these are the steps I am using to generate an access policy and generate a SAS token that references that access policy:
- In the Azure Storage Explorer, I browse to blob storage and find the specific container I want to grant access to. I right-click and select "Manage Access Policies".
- I then provide all permissions to this policy, and provide an end date that is 20 years from now.
- After clicking "Save", I go back to my container list and right-click on that container once more and select "Get Shared Access Signature".
- Within the Shared Access Signature Dialog, I reference my access policy.
- Upon clicking "Create", I have my Shared Access Signature with an attached policy.
- I then simply copy/paste my storage account name, container name, and auth key into the code shown above. For the auth key, I use the "Query String" field shown in my SAS Signature dialog. For example:
Query String field is used as auth key, according to the docs
string storageAccountName = "ringclone";
string containerName = "ringcentral-archives";
string authenticationKey = "?sv=2018-03-28&si=ringclone-access-policy&sr=c&sig=************************"; // retrieved from the "Query String" field in storage explorer.
However, I am getting a 403 error when trying to list the blobs in my container. What am I doing wrong?