0
votes

Can someone please assist me? I am getting below error while accessing blob container by using SAS token with storage emulator -

Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature

System.AggregateException: One or more errors occurred. (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:c3d554bf-ae0c-413d-ba15-ef888f141864 Time:2020-08-19T08:18:01.6796671Z Status: 403 (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.) ErrorCode: AuthenticationFailed

Headers: Server: Microsoft-HTTPAPI/2.0 x-ms-request-id: c3d554bf-ae0c-413d-ba15-ef888f141864 x-ms-error-code: AuthenticationFailed Date: Wed, 19 Aug 2020 08:18:01 GMT Content-Length: 498 Content-Type: application/xml**

Expected behavior What is the expected behavior?

Below are the Exception or Stack Trace details - ---> Azure.RequestFailedException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:0b506bfc-ba50-4519-924f-6072c5ba829d Time:2020-08-19T08:47:57.3367759Z Status: 403 (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.) ErrorCode: AuthenticationFailed

Headers: Server: Microsoft-HTTPAPI/2.0 x-ms-request-id: 0b506bfc-ba50-4519-924f-6072c5ba829d x-ms-error-code: AuthenticationFailed Date: Wed, 19 Aug 2020 08:47:57 GMT Content-Length: 498 Content-Type: application/xml

at Azure.Storage.Blobs.BlobRestClient.Service.GetPropertiesAsync_CreateResponse(ClientDiagnostics clientDiagnostics, Response response) at Azure.Storage.Blobs.BlobRestClient.Service.GetPropertiesAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri resourceUri, String version, Nullable`1 timeout, String requestId, Boolean async, String operationName, CancellationToken cancellationToken) at Azure.Storage.Blobs.BlobServiceClient.GetPropertiesInternal(Boolean async, CancellationToken cancellationToken) at Azure.Storage.Blobs.BlobServiceClient.GetPropertiesAsync(CancellationToken cancellationToken)

I am referring sample example - https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/storage/Azure.Storage.Blobs/samples/Sample02_Auth.cs

Below is the code to reproduce -

BlobSasBuilder sasBuilder = new BlobSasBuilder {
BlobContainerName = "myTestContainer",
Resource = "c",
//StartsOn = DateTimeOffset.UtcNow,
//ExpiresOn = DateTimeOffset.UtcNow.AddHours(1)
ExpiresOn = DateTimeOffset.MaxValue
};  
//Allow read access
        sasBuilder.SetPermissions(BlobContainerSasPermissions.Read);
        
        StorageSharedKeyCredential credential =
            new StorageSharedKeyCredential("Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "devstoreaccount1");

        // Use the key to get the SAS token.
        string sasToken = sasBuilder.ToSasQueryParameters(credential).ToString();

        Console.WriteLine("SAS for blob container is: {0}", sasToken);
        Console.WriteLine();

        // Build a SAS URI
        UriBuilder sasUri = new UriBuilder(containerClient.Uri);
        sasUri.Query = sasToken;

        // Create a client that can authenticate with the SAS URI
        BlobServiceClient service = new BlobServiceClient(sasUri.Uri);
        
         // Make a service request to verify we've successfully authenticated
        await service.GetPropertiesAsync(); //Note - Receiving above error while calling this function
Please try add the list permission as per this code: sasBuilder.SetPermissions(BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);Ivan Yang
Tried but no luck .. still getting same error sasBuilder.SetPermissions(BlobContainerSasPermissions.List); sasBuilder.SetPermissions(BlobContainerSasPermissions.All); sasBuilder.SetPermissions(BlobContainerSasPermissions.Read);sanjay kulkarni