question

JacobMarble avatar image
0 Votes"
JacobMarble asked JacobMarble commented

401 The input date header is invalid format

My requests to the CosmosDB API (both the emulator and an instance in Azure) fails with 401 Unauthorized, and this body:

 {"code":"Unauthorized","message":"The input date header is invalid format. Please pass in RFC 1123 style date format.\r\nActivityId: 0b8ed7e2-f634-492b-990d-72bc67f7513d, Microsoft.Azure.Documents.Common/2.14.0"} 

I'm using golang, so need to construct the hashed token signature for a master token, as described in the docs. My implementation matches the documented example, which is to say:

 verb := "GET" 
 resourceType := "dbs" 
 resourceLink := "dbs/ToDoList" 
 masterKey := "dsZQi3KtZmCv1ljt3VNWNm7sQUF1y5rJfC6kv5JiwvW0EndXdDku/dkKBp8/ufDToSxLzR4y+O/0H/t4bQtVNw==" 
 nowTime, _ := time.Parse(time.RFC1123, "Thu, 27 Apr 2017 00:51:12 GMT") 

 // got matches expect 
 got, _ := hashTokenSignature(verb, resourceType, resourceLink, masterKey, nowTime) 
 expect := "c09PEVJrgp2uQRkr934kFbTqhByc7TVr3OHyqlu+c+c=" 

Now, create the auth token:

 // got matches expect 
 got := url.QueryEscape("type=master&ver=1.0&sig=c09PEVJrgp2uQRkr934kFbTqhByc7TVr3OHyqlu+c+c=") 
 expect := "type%3Dmaster%26ver%3D1.0%26sig%3Dc09PEVJrgp2uQRkr934kFbTqhByc7TVr3OHyqlu%2Bc%2Bc%3D" 

Now let’s consider the date header. The string I use for x-ms-date is identical to the one I use in the signature constructor: Thu, 27 Apr 2017 00:51:12 GMT Case does not seem to matter; the error persists whether the RFC 1123 date string is lower-cased or not.

Here is an example query against the emulator, running locally in Docker.

Signature payload (plus an extra newline character):

 get
 dbs

 sat, 07 aug 2021 23:39:32 pdt

Master key:

 C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==

Request:

 Method: GET
 URI: https://localhost:8081/dbs/

 X-Ms-Version: "2018-12-31"
 X-Ms-Date: "Sat, 07 Aug 2021 23:39:32 PDT"
 Authorization: "type%3Dmaster%26ver%3D1.0%26sig%3Dhgfum5w73%2FmoXN%2BZDXt1BxmmmGRbUxaRSresf24ZeRY%3D"

Response:

 401 Unauthorized {"code":"Unauthorized","message":"The input date header is invalid format. Please pass in RFC 1123 style date format.\r\nActivityId: bc0c28b1-987c-46c3-ad1c-027f1e9781af, Microsoft.Azure.Documents.Common/2.14.0"}
azure-cosmos-db
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@JacobMarble-4169 Thank you for reaching out.

Could you please check your Cosmos DB account type?
Querying resources using REST is supported with SQL API only. Gremlin, Cassandra or Table API are not currently supported.


0 Votes 0 ·
JacobMarble avatar image JacobMarble KalyanChanumolu-MSFT ·

Hello @KalyanChanumolu-MSFT . How do I check the account type? I'm certain that I created the account as SQL, but I don't know how to double check that.

Also, I believe the Docker emulator only supports the SQL API.

0 Votes 0 ·

You can check it from Data Explorer blade on the Azure portal

121599-image.png

0 Votes 0 ·
image.png (62.7 KiB)

You can develop applications using Azure Cosmos DB Emulator with the SQL, Cassandra, MongoDB, Gremlin, and Table API accounts.
However, the data explorer in the emulator fully supports viewing SQL data only; the data created using MongoDB, Gremlin/Graph and Cassandra client applications it is not viewable at this time.
You can still connect to the respective API endpoint and query data.

0 Votes 0 ·
Show more comments

0 Answers