question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

I’m doing tests using MSI to access / manipulate a storage account. I’m getting a token using the following code:

        static string GetUserOAuthToken(string tenantId, string applicationId, string clientSecret)
        {
            const string ResourceId = "https://storage.azure.com/";
            const string AuthInstance = "https://login.microsoftonline.com/{0}/";

            string authority = string.Format(CultureInfo.InvariantCulture, AuthInstance, tenantId);
            AuthenticationContext authContext = new AuthenticationContext(authority);

            var clientCred = new ClientCredential(applicationId, clientSecret);
            AuthenticationResult result = authContext.AcquireTokenAsync(
                                                ResourceId,
                                                clientCred
                                                ).Result;
            return result.AccessToken;
        }

with the token, I’m trying to upload a blob, but getting the following error:

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

PS: I don’t have Application Insights, so it’s not related with #416

An here’s the code to access the blob:

TokenCredential tokenCredential = new TokenCredential(token);
StorageCredentials storageCredentials = new StorageCredentials(tokenCredential);
CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(storageCredentials, "SECRET", "core.windows.net", useHttps: true);

CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
blobClient.AuthenticationScheme = AuthenticationScheme.Token;

CloudBlobContainer blobContainer = blobClient.GetContainerReference("test");

var blob = blobContainer.GetBlockBlobReference("asdasdasdasd.txt");
blob.UploadTextAsync("oi").Wait();

Using the version 9.3.3 of WindowsAzure.Storage lib

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
seanmcc-msftcommented, Oct 4, 2019

Here’s an example of using an Oauth token:

        static string GetUserOAuthToken()
        {
            var activeDirectoryAuthEndpoint = "https://login.windows.net";
            var activeDirectoryTenantId = "activeDirectoryTenantId";
            var activeDirectoryApplicationId = "activeDirectoryApplicationId ";
            var activeDirectoryApplicationSecret = "activeDirectoryApplicationSecret";

            var authority = String.Format(activeDirectoryAuthEndpoint + "/" + activeDirectoryTenantId);

            var credential = new ClientCredential(activeDirectoryApplicationId, activeDirectoryApplicationSecret);

            var context = new AuthenticationContext(authority);
            var result = context.AcquireTokenAsync("https://storage.azure.com", credential).Result;

            return result.AccessToken;
        }
        static void Main()
        {
            var accessToken = GetUserOAuthToken();
            var tokenCredential = new TokenCredential(accessToken);
            var storageCredentials = new StorageCredentials(tokenCredential);
            var storageAccount = new CloudStorageAccount(storageCredentials, "accountName", string.Empty, useHttps: true);
            var cloudBlobClient = storageAccount.CreateCloudBlobClient();
            var cloudBlobContainer = cloudBlobClient.GetContainerReference("mycontainer");
            cloudBlobContainer.CreateIfNotExists();
        }
1reaction
ddobriccommented, May 3, 2020

In my case, I have restarted the docker desktop (host). If figured out that this happen when the machine goes to sleep.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AzureStorage Blob Server failed to authenticate ...
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. The error ...
Read more >
Azure Blob Storage fails to authenticate: "Make sure the ...
Azure Blob Storage fails to authenticate: "Make sure the value of Authorization header is formed correctly including the signature".
Read more >
Microsoft.Azure.Storage.StorageException: Server failed to ...
StorageException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. #176.
Read more >
Error "Server failed to authenticate the request" while ...
If request authentication is failing, that means there is an issue with the SAS token provided while configuring the job. You need to...
Read more >
Error Message: “Server failed to authenticate the request. ...
Error Message: “Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found