azure-sdk-for-net: AuthenticationFailed when using SAS token based authentication to read Azure Table

I have been using the snippet below to create and Azure.Data.Tables:12.1.0 and having intermittent authentication failure. I have tried to setup start date to -1 day and also tried without start date. It works once out of 4 times.

Error:

Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:cf1c3480-2002-0069-32cf-7c6cb1000000
Time:2021-07-19T18:52:47.4799506Z
Status: 403 (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.)
ErrorCode: AuthenticationFailed

Content:
{"odata.error":{"code":"AuthenticationFailed","message":{"lang":"en-US","value":"Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:cf1c3480-2002-0069-32cf-7c6cb1000000\nTime:2021-07-19T18:52:47.4799506Z"}}}

Headers:
x-ms-request-id: cf1c3480-2002-0069-32cf-7c6cb1000000
x-ms-error-code: REDACTED
Content-Length: 299
Content-Type: application/json
Date: Mon, 19 Jul 2021 18:52:46 GMT
Server: Microsoft-HTTPAPI/2.0

Snippet:

      
       private static string connectionString(string sasKey)
        {
            string tableEndpoint = $"https://{StorageAccountName}.{TableStorageBaseURI}/";
            string connecitonString1 = $"TableEndpoint={tableEndpoint};SharedAccessSignature={sasKey}";

            return connecitonString1;
        }

        private static string GetAccountSASToken(StorageSharedKeyCredential key)
        {
            // Create a SAS token that's valid for one hour.
            AccountSasBuilder sasBuilder = new AccountSasBuilder()
            {
                Services = AccountSasServices.Tables,
                ResourceTypes = AccountSasResourceTypes.All,
                ExpiresOn = DateTimeOffset.UtcNow.AddHours(1),
                Protocol = SasProtocol.Https,
                StartsOn = DateTimeOffset.UtcNow.AddDays(-1)
            };

            sasBuilder.SetPermissions(AccountSasPermissions.Read |
                AccountSasPermissions.Write);

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

            Console.WriteLine("SAS token for the storage account is: {0}", sasToken);
            Console.WriteLine();

            return sasToken;
        }

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

I should have a PR out in the next couple days for this.