Description
I have a functioning Parse Server up and running and an iOS app successfully accessing it. Everything has been running well for a couple of years.
I didn't add a javascriptKey
when setting up the server, but want to add one now to support some web development. However, adding this key to my server configuration via index.js
results in all requests from the app failing as unauthorized. It is something specific about the javascriptKey
property, since adding a javascriptKey2
instead does not produce the issue. It seems like the server is expecting some additional authorization to be sent by the iOS app when there is a javascriptKey
set on the server, but the iOS app doesn't know or care about any javascriptKey
. I'm not even sure it is possible to set a javascript key via the iOS SDK.
There is no logging from the server for this. I can run the server locally and nothing is logged when the failed request is returned.
Steps to reproduce:
- Set up a Parse Server without a
javascriptKey
and confirm that your app can access it. - Add a
javascriptKey
to the server.
Expected: the app continues to access the server as before.
Actual: all requests fail as "unauthorized"
I am on Parse Server 4.2.0. I couldn't find any mention of this issue in any releases since (or previously) then so am hopeful there is
a common solution that doesn't involve upgrading to 5.x quite yet!
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 || 'myAppId',
masterKey: process.env.MASTER_KEY || '',
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
javascriptKey: '123',
appName: '<App Name>',
publicServerURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
...
}
Activity
parse-github-assistant commentedon Jun 25, 2022
Thanks for opening this issue!
mtrezza commentedon Jun 26, 2022
It would make sense for Parse Server to enforce a key for every client type if any client key is set. Otherwise you could just use a different client and I don't think Parse Server has an option to disable certain client types.
From the docs:
The docs may be ambiguous about that, but I think in hosted Parse that was the behavior, and the intention when open-sourcing was surely to replicate that behavior. Did you try setting a client key also for the iOS SDK?
benpackard commentedon Jun 26, 2022
Yep adding a client key to each platform's app is what's required, many thanks. Unfortunately it probably means a long delay or cancelation for my web project since I will need all of my users to update first or else their apps will just stop working overnight.
I think the prevailing advice everywhere you look these days is "You don't need a client key anymore" so I guess not many people have tried adding one later. It might be better that we try to recommend always adding a client key for future-compatibility if this current behavior is going to be enforced by the server.
Alternatively, am I missing something and the javascript key should not be necessary either? My understanding is that we must provide it for server-side data fetching for our React web page. Perhaps a question for the web SDK team but maybe you know.
As for the docs specifically, I think this would be a helpful change:
Let me know if you would like a PR for this.
benpackard commentedon Jun 26, 2022
I just found this similar conversation which confirms your diagnosis: #159 (comment)
It is a good example of the 'prevailing advice' I mentioned:
This is common advice when people ask about client keys. So one of these is true:
Or,