parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

"error":"unauthorized" on debian 8.3.0

Open maurosoft1973 opened this issue 10 years ago • 7 comments

Hello! I installed Node.js (version 5.6.0) and mongodb on a virtual machine.

To check if the environment works, I tried to enter from console: curl -X POST -H 'X-Parse-Application-Id: AppId "-H" Content-Type: application / json "-d' {" score ": 1337," playername ":" Sammy "," cheatMode ": false} 'http://localhost:1337/parse/classes/gamescore where to AppId I replaced my AppId. I always get the following error: {"error": "unauthorized"}

I created a virtual machine with Windows Server 2012, the same configuration for nodejs and mongo, testing the same script,it's works.

I do not understand why

maurosoft1973 avatar Feb 18 '16 09:02 maurosoft1973

Hi,

Can you check that the index.js are the same into your two servers. I had the same problem, and it was because I did not put the serverURL into my index.js file (documentation was incomplete at that moment). So, it still tried to communicate with https://api.parse.com that returned this.

This is how it should look with the serverURL option.

...
// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var api = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/dev',
  cloud: '/home/myApp/cloud/main.js', // Provide an absolute path
  appId: 'myAppId',
  masterKey: '', //Add your master key here. Keep it secret!
  fileKey: 'optionalFileKey',
  serverURL: 'http://localhost:' + port + '/parse' // Don't forget to change to https if needed
});
...

Kira2 avatar Feb 18 '16 10:02 Kira2

Hi Kira2! thanks for your suggestion, but also adding the parameter serverURL the problem remains.

The configuration is identical (windows and linux)

maurosoft1973 avatar Feb 18 '16 10:02 maurosoft1973

@simonbengtsson i dont'use the https://api.parse.com/1 as default serverURL, please view configuration in previous comment, it is set correctly. the problem it occurs only on debian enviroment, the same configuration on windows platform not generate error.

why?

maurosoft1973 avatar Feb 18 '16 11:02 maurosoft1973

I mainly referenced because of @maurosoft1973 comment.

One way to debug this is to systematically follow the request. I would first add a console.log(method, url, data, headers); the first thing in node_modules/parse/lib/node/RESTController.js::ajax() (currently line 80). Then check those variables to see if they are as expected. If they are things gets interesting. If the log message is not printed you can check if the error is thrown in any of those places in Parse Server.

  • node_modules/parse-server/lib/schemas.js line 89
  • node_modules/parse-server/lib/middlewares.js currently line 169
  • node_modules/parse-server/lib/global_config.js currently line 31

Let me know your findings.

simonbengtsson avatar Feb 18 '16 12:02 simonbengtsson

@simonbengtsson i resolve problem, thanks!

in the linux enviroment, the restAPIKey has a value. remove, works.

this is my configuration

var api = new ParseServer({ databaseURI: 'mongodb://localhost:27017/dev', cloud: '/cloud/main.js', appId: '', masterKey: '', serverURL: 'http://localhost:' + port + '/parse', push: { android: { senderId: '', apiKey: '' } } });

only appId ed masterKey is required ...

maurosoft1973 avatar Feb 18 '16 14:02 maurosoft1973

I'm glad! Out of curiosity, how did the rest key only end up in debian? Environment variable?

simonbengtsson avatar Feb 18 '16 14:02 simonbengtsson

no enviroment variable, the paste rest Key accidentally in my configuration and I was convinced of the contrary!

maurosoft1973 avatar Feb 18 '16 15:02 maurosoft1973