user3376563
user3376563

Reputation: 313

Parse Server - How to enable REST API Key on Heroku

I am migrating from Parse.com to Heroku... I have successfully installed Parse Server, but it seems I am able to connect to my classes via PHP SDK without requiring a master key or restapi key.

As per the instructions, I added the restApiKey in index.js as such:

var api = new ParseServer({
   databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
   cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
   appId: process.env.APP_ID || 'xxxxxx',
   masterKey: process.env.MASTER_KEY || 'zzzzz',
   restAPIKey: 'yyyyyy',
   serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
   liveQuery: {
     classNames: ["Posts", "Comments"]
}
});

I have committed this code and deployed on heroku. But when I try from PHP as:

ParseClient::initialize('xxxx', '', '');

With Rest Key value left blank, Parse does NOT throw an unauthorized error. However, if I do the same with my set up on Parse.com, it does throw an error.

What am I missing? Thank you

Upvotes: 2

Views: 571

Answers (1)

user3376563
user3376563

Reputation: 313

So after lots of trial and error, it started working and I believe this is what I did to make it work.

You need to add all the optional keys: restAPIKey, dotNetKey, clientKey, javascriptKey, to index.js as part of the initialization. Then you must set values for ALL of them. If even one of them is not set, restAPIKey is not enforced. I didn't find this anywhere in the docs and just stumbled upon it. I hope this helps someone.

Upvotes: 7

Related Questions