Unauthorized access service with StorageService.UpdateDocumentWithId

0 votes

I am experiencing new error with App42 Cloud interface. We are using it almost half of year without problem on iOS and Android. Now we've migrated our code to Win8 and Windows Phone 8.

We are using cocos2dx SDK implementation for all platforms.

Yesterday I made several tests on WP8 and Windows 8.

1. Windows 8 is working ok

2. Windows Phone 8 - Finding documents is ok but when I want to insert or update existing document I've got error about unauthorized access. The Request is exactly the same as on Win8. 99% of code is the same (the only difference is in low level: curl on WP8 vs. http_request on Win8).

Can you please tell me in which case the server returns this error? What can be wrong?


asked Aug 21, 2014 in App42 Cloud API-BaaS by info (10 points)

1 Answer

0 votes


UnAuthorized Access (1401) Exception comes when signature is false.

There are different reasons behind it:

      - Either your API Key & Secret Key is not correct

      - Or the device time is not correct on which app is running, i.e. time stamp is not correct while making the request.

      - The post body is not a valid json etc.

You can check these things inside InsertJsonDocument API code:

       map<string, string> signParams;

        string timestamp = Util::getTimeStamp();


        signParams["dbName"] = dbName;

        signParams["collectionName"] = collectionName;

       string storageBody = BuildStorageBody(json);

        signParams["body"] = storageBody;

       string signature = Util::signMap(secretKey, signParams);

The above code is responsible for creating the signature, you can go through it and check what is going wrong.

If possible, please print the signParams, headers and URL and share with us so that we can also try to detect what is wrong in the request params.

Let us know if you need any other info related to this.

answered Aug 21, 2014 by rajeev.etc (1,660 points)
Thank you.

I cannot see any error in our data. Here is dump:


+        [0]    "loggedInUser:1375652327"
+        [1]    "apiKey:1ca6ab84c248849cdadcb2ce9abea428f133a58b46f853fdfbda9b752c56842b"
+        [2]    "timeStamp:2014-08-21T16:50:36.000Z"
+        [3]    "signature:WfY9D7VNyPuZSm1Fl3CnbNcAVPs%3D"
+        [4]    "version:1.0"


This returns:

        _result    401    int
+        _body    "{\"app42Fault\":{\"httpErrorCode\":401,\"appErrorCode\":1401,\"message\":\"UnAuthorized Access\",\"details\":\"Client is not authorized\"}}"
        isSuccess    false
        httpErrorCode    401
        appErrorCode    1401
+        errorDetails    "Client is not authorized"
+        errorMessage    "UnAuthorized Access"

I've checked timestamp, json is valid, signature should be ok since FindDocument calls are successful with the same configuration.

Thank you for any help.

Everything looks fine from the logs you shared. It will be easy for us to track the issue if you can share the SDK code you are using for now. You can share the code on support@shephertz.com. Please remove your API_KEY from the above comment for security reasons.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com