Azure-docs: Authentication error in Node.js CosmosDB SDK by using @azure/cosmos library v3.0.4: "Required Header authorization is missing"

Created on 26 Jul 2019  Â·  8Comments  Â·  Source: MicrosoftDocs/azure-docs

Following the tutorial "Build a Node.js console app with the JavaScript SDK to manage Azure Cosmos DB SQL API data" there is an error when executing the node file "app.js":

Completed with error {"code":401,"body":{"code":"Unauthorized","message":"Required Header authorization is missing. Ensure a valid Authorization token is passed.rnActivityId: 9f2f4023-1b37-451e-bc6e-edcfb5f3c734, Microsoft.Azure.Documents.Common/2.4.0.0"}...

After struggling with that error, It was found that the issue happens by using the version 3.0.4 of @azure/cosmos library. If I uninstall the library (by the command npm uninstall @azure/cosmos from a terminal in the main folder) and re install it using the 2.1.7 version (npm install @azure/[email protected] --save) then the authentication error dissapears.

Is there something missing in the latest version of the library, which produce the Auth error? Or does something change in the latest and this change is not well documented on the tutorial?

I hope this can help to fix a possible issue with the library or give some lights to people, who is also having troubles with that Auth error.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 assigned-to-author cosmos-dsvc cosmosdb-sqsubsvc doc-bug in-progress triaged

Most helpful comment

this resolves fine if you use the full connection string
const client = new CosmosClient("AccountEndpoint=https://test-account.documents.azure.com:443/;AccountKey=c213asdasdefgdfgrtweaYPpgoeCsHbpRTHhxuMsTaw==;")

All 8 comments

@kilmfer91 Thanks for the feedback. We are actively investigating and will get back to you soon.

I also got this error today!

I also got this error today.

2019-07-30T15:57:05.533 [Error] Executed 'Functions.HttpTriggerallan' (Failed, Id=b75a09c2-178c-491f-a706-1ff62aadd308)
Result: Failure
Exception: Error: Required Header authorization is missing. Ensure a valid Authorization token is passed.
ActivityId: 5ff9b804-c1b5-448a-bb49-3380aff62aa6, Microsoft.Azure.Documents.Common/2.5.1
Stack: Error: Required Header authorization is missing. Ensure a valid Authorization token is passed.
ActivityId: 5ff9b804-c1b5-448a-bb49-3380aff62aa6, Microsoft.Azure.Documents.Common/2.5.1
at D:[email protected]:6297:39
at Generator.next ()
at fulfilled (D:homesitewwwrootnode_modulestslibtslib.js:107:62)
at
at process._tickCallback (internal/process/next_tick.js:188:7)

this resolves fine if you use the full connection string
const client = new CosmosClient("AccountEndpoint=https://test-account.documents.azure.com:443/;AccountKey=c213asdasdefgdfgrtweaYPpgoeCsHbpRTHhxuMsTaw==;")

@southpolesteve - can you take a look?

@regenbauma @angie4u @kilmfer91 Sorry for the trouble! The sample is using the 2.x.x version of the SDK, but the 3.x.x version has a slightly different constructor: https://github.com/Azure/azure-cosmos-js/blob/master/changelog.md#improved-client-constructor-options-246

I'll get the sample updated ASAP

@regenbauma @angie4u @kilmfer91 The code is fixed, the above PR should address the doc updates.

We will now close this issue if there aren't any further questions.

please-close

this resolves fine if you use the full connection string
const client = new CosmosClient("AccountEndpoint=https://test-account.documents.azure.com:443/;AccountKey=c213asdasdefgdfgrtweaYPpgoeCsHbpRTHhxuMsTaw==;")

It worked for me thank you .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

varma31 picture varma31  Â·  3Comments

spottedmahn picture spottedmahn  Â·  3Comments

ianpowell2017 picture ianpowell2017  Â·  3Comments

monteledwards picture monteledwards  Â·  3Comments

paulmarshall picture paulmarshall  Â·  3Comments