Azure / azure-cosmosdb-node

We recently announced deprecation of JS v1 SDK and this repo. Starting September 2020 Microsoft will not provide support for this library. Existing applications using library will continue to work as-is. We strongly recommend upgrading to @azure/cosmos library.
https://github.com/Azure/azure-sdk-for-js
MIT License
142 stars 107 forks source link

Unauthorized, The input authorization token can't serve the request #82

Closed mauricionr closed 7 years ago

mauricionr commented 8 years ago

Localhost everything works fine, but when a i made a deploy i'm getting this error.

ActivityId: 39d58ef7-0df9-436d-a803-06991ee62424 { code: 401, body: '{"code":"Unauthorized","message":"The input authorization token can\'t serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: \'post\ndbs\n\nthu, 29 oct 2015 18:52:39 gmt\n\n\'\r\nActivityId: 39d58ef7-0df9-436d-a803-06991ee62424"}' }

any guess?

Thanks!

akhadem commented 8 years ago

same

ghost commented 8 years ago

Cannot repro this issue. Can someone please post a repro project.

What are you deploying to? Azure Web applications, VMS, something else?

mauricionr commented 8 years ago

In my case is an Azure nodjes web app with Azure DocumentDB

ghost commented 8 years ago

Is your node.js web app and the DocumentDB in the same Azure region?

ghost commented 8 years ago

Is this still an issue?

matthiasotto commented 8 years ago

Just encountered this:

{"The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'get\n\n\ntue, 09 feb 2016 18:46:42 gmt\n\n'\r\nActivityId: 143aa10b-ec48-4788-9306-6be7eaf15b78"}

maodd commented 8 years ago

I got same issue when running the databasemanagement.js sample: https://github.com/Azure/azure-documentdb-node/blob/master/samples/DatabaseManagement/app.js

maodd commented 8 years ago

never mind, updated client lib from 0.9.4 to 1.5.5. problem went away.

ghost commented 8 years ago

@matthiasotto @mauricionr @akhadem could you please confirm which version of the node SDK you are using? If you are using an old version of the SDK could you please upgrade to the latest version and try again.

syantien commented 8 years ago

Hi. I also get this error: Microsoft.Azure.Documents.DocumentClientException: The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'post docs xwfmaksjxqa= sat, 05 mar 2016 05:53:08 gmt.

I seem to get this randomly. My SDK version is 1.5.3.

ghost commented 8 years ago

@syantien that error looks like .NET? are you using .NET SDK or the Node SDK?

thivy commented 8 years ago

@ryancrawcour I had the same error. It turns out when I copied the PRIMARY KEY from the portal it only copied what you see on screen.

When you guys copy the PRIMARY KEY make sure to copy using Click to Copy button, instead of using the mouse select.

julielerman commented 8 years ago

I'm getting this same error after updating to current SDK and using Upsert instead of replace. All of my queries are fine. I have been using the key for a long time with replace working as expected. I'll keep googlebinging. I'm using the Q promises wrapper, btw.

ghost commented 8 years ago

If you're using ID based routing, i.e. your links contain your own IDs not the internal system rid e.g. dbs/mydatabaseid/colls/mycollectionid then check that you don't have a trailing /

julielerman commented 8 years ago

getting closer. I started out with this (following an example in the blog post that announced no more dependency self links) var docLink = "dbs/Ninjas/colls/Ninjas/docs/"+ item.Id;

now I'm down to

var docLink = "dbs/Ninjas/colls/Ninjas" and letting upsert find the id in the item passed into the 2nd parameter.

No error.

Data not updated either ;), but I'm sure that's something silly. Will update you . And thanks! Given that you're not on the documentdb team anymore. :)

UPDATE & this last bit is unrelated to original question:

found it. Somewhere along the line I had specified the Id property as [capital]Id so it wasn't matching [lowercase]id in the database and doing an insert instead

So in the end: var docLink = "dbs/Ninjas/colls/Ninjas" was the correctly formatted string to pass in as first parameter to the upsert. Thanks

ghost commented 8 years ago

Yeah, this is still an open issue to resolve this trailing / thing in the node.js driver properly. It shouldn't care if there's a trailing / or not.

Just thought I'd unblock you seeing as I knew what the cause was.

rnagpal commented 8 years ago

Thanks Ryan for jumping in here!

I'll look into fixing the trailing / in the Node SDK.

julielerman commented 8 years ago

thanks also for the node sdk and for the q wrapper!! See https://github.com/julielerman/AureliaDocDB for how I implemented it. Want me to update your sample documentation? ;)

mauricionr commented 8 years ago

@ryancrawcour sorry for my long delay, I'm currently not using documentDB. I've changed to azure mobile app service

1N50MN14 commented 7 years ago

Is there anyone maintaining the node.js SDK at all? I'm surprised such a critical issue is still standing we're pretty much unable to use the SDK because of it..

rnagpal commented 7 years ago

@1N50MN14 Looks like the thread diverged. Are you running into the auth issue(401 error)? Can you send me the error message with AcivityId so that we can look into it? Sample code where you hit this issue will help us repro. You get an authorization error even when the Id contains an invalid char, so please verify that the id of the resource doesn't contain any of the chars listed in https://msdn.microsoft.com/en-us/library/azure/microsoft.azure.documents.resource.id.aspx#P:Microsoft.Azure.Documents.Resource.Id

1N50MN14 commented 7 years ago

@rnagpal Yes you were right there, in addition to that I also had a malformed collection link somehow I assumed 'dbs/'+databaseId+'/colls/'+collectionId+'/docs' to be used with creating documents, omitting /docssolved it

moderakh commented 7 years ago

I am closing it (as it seems the problem is solved). If you think this is a bug in most recent version of nodejs sdk please feel free to reopen.

paullintilhac commented 6 years ago

I had the same error, and resolved it by using my primary read-only key from azure instead of my primary read/write key

crowster commented 6 years ago

My problem was very simple, I was using a bad url

vindicatesociety commented 6 years ago

@julielerman how did you get docs out of your path. I'm seeing the trailing "docs" in the swift sdk. "dbs/Ninjas/colls/Ninjas/docs/"

davidljuba15031979 commented 4 years ago

My problem was wrong connection string.

In Azure Portal, I checked and compared AzureCosmosDBConnectionString from

Function app -> Configuration

and

Azure Cosmos DB Account -> Keys -> Primary connection string

They were different.

faustofjunqueira commented 3 years ago

Hy people, At this moment, I have the same problem. In my case, my clock is wrong! I fix the time and redo the request. I hope help someone.

gerardsimons commented 2 years ago

Forgot to change the URL when I did change the key, thanks for the comments here for pointing me in the right direction!

Aodhanob commented 1 year ago

o Cop

THIS IS THE CAUSE!!!

THANK YOU!!!

ankitgupta2oct commented 6 months ago

@ryancrawcour I had the same error. It turns out when I copied the PRIMARY KEY from the portal it only copied what you see on screen.

When you guys copy the PRIMARY KEY make sure to copy using Click to Copy button, instead of using the mouse select.

Thanks, This solved the issue for me.