You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Query in Parse Cloud returns "unauthorized" error #356
The command query.find always returns error in Parse Cloud. The response is Response Body : {"code":141,"error":"Error: undefined unauthorized"}.
The request is being done by Swift SDK.
It looks that Parse Cloud can't access the classes of Parse Server.
What could be possible reasons ?
Parse.Cloud.beforeSave("Message", function(request, response) {
if (!request.object.get("uniqueCode")) {
response.error('A Message must have a uniqueCode.');
} else {
var Message = Parse.Object.extend("Message");
var query = new Parse.Query(Message);
query.equalTo("uniqueCode", request.object.get("uniqueCode"));
query.find({
success: function(results) {
if (results.length > 0) {
response.success();
} else {
response.error("A Message with this uniqueCode already exists.");
}
},
error: function(error) {
response.error("Error: " + error.code + " " + error.message);
}
});
}
});
My settings is according to the Parse Server example:
It is hosted in Heroku and the env vars below are configured.
var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;
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 || '',
clientKey: process.env.CLIENT_KEY || ''
});
If I remove the keys ( var api = new ParseServer() ), will the server still work and will it be able to be accessed by mobile SDK ???
The request to insert a new message (that triggers the beforeSave()) is done by Swift SDK.
I think I have the same problem as @Leo-One. I can't use any queries in cloud code using the parse server as they return with the error {"code":141,"error":"Error: undefined unauthorized"}.
When diving into the source to troubleshoot I saw that all the queries (find, first, get etc) results in node_modules/parse-server/node_modules/parse/lib/node/RESTController.js:ajax() sending a post request to https://api.parse.com/1/classes/MyObject which of course will result in unauthorized as parse doesn't know anything about my local app. I tried sending a get request to http://localhost:1337/parse/classes/MyObject which works and returns objects as expected.
I'm probably missing something here, but what would you have to do to get queries working in cloud code with a local parse server?
@simonbengtsson Just out of curiosity, what is the hosting solution are you using ?
I am using Heroku and I tried: serverURL: 'https://localhost:1337/parse' or serverURL: 'http://localhost:1337/parse' or serverURL: 'https://localhost:' + port + '/parse'-> received {"code":141,"error":"Error: 100 XMLHttpRequest failed: \"Unable to connect to the Parse API\""}
serverURL: 'http://localhost:' + port + '/parse'-> received {"code":141,"error":"Error: undefined unauthorized"}
Also getting a similar response (141 / unauthorised) via Cloud Code. App ID matches client-side and in the ParseServer constructor + client keys not defined in client/server. Locally regular CloudCode functions (like the default hello function in parse-server-example) work just fine, it seems to be queries that have issues. Both all fail when deployed to heroku.
Parse.Cloud.define('validateEmail', function(req, res) {
// Get the email address of the user we are going to check
var email = req.params.email;
// Execute query with Parse
var query = new Parse.Query("ObjectTest");
query.equalTo('email', email);
query.find({
success: function(result) {
res.success(result);
},
error: function(err) {
res.error(err);
}
});
});
(nothing declared outside of Parse.Cloud.define, Parse not re-imported etc)
The serverURL is defined and matches that defined by the client. I have tried fully qualified URL's in the client-side (http://www etc) and a relative path, both produce error 141 for some odd reason!
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://XXXXXXX',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'XXXXXXX',
masterKey: process.env.MASTER_KEY || 'XXXXXXX',
clientKey: process.env.CLIENT_KEY || '',
serverURL: 'http://www.XXXXXXX.com/parse'
});
(XXXXXXX's subbed in place of real values, both match server/client side)
@simonbengtsson Think I sussed it! The environment variable APP_ID had an extra character at the end which likely caused the requests to (rightly) fail. Thanks for the help! 👍
You're explicitly setting the client key to a null value in that code..
Change it to literally any string like 'clientKeyIsNotUsed' and it should
stop telling you that.
03-24 21:23:40.048 4014-4628/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:40.290 4014-4633/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:41.707 4014-4634/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:44.327 4014-4636/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:49.207 4014-4639/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:58.707 4014-4642/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:34:19.855 4698-4698/? I/Parse: Save Failed
03-24 21:36:16.718 4791-4791/? I/Parse: Save Failed
03-25 00:44:10.737 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS in package: com.android.shell at: Binary XML file line #101
03-25 00:44:10.787 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.CONFIGURE_WIFI_DISPLAY in package: com.android.systemui at: Binary XML file line #119
03-25 00:44:11.266 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.WRITE_CONTACTS in package: com.android.email at: Binary XML file line #40
03-25 00:44:11.827 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.WAKE_LOCK in package: com.google.android.apps.maps at: Binary XML file line #96
03-25 00:44:12.362 1300-1300/? W/PackageParser: No actions in intent filter at /data/app/ApiDemos/ApiDemos.apk Binary XML file line #3082
03-25 00:44:12.362 1300-1300/? W/PackageParser: No actions in intent filter at /data/app/ApiDemos/ApiDemos.apk Binary XML file line #3088
03-25 00:44:14.607 1300-1300/? W/System.err: at com.android.internal.alsa.AlsaCardsParser.scan(AlsaCardsParser.java:109)
03-25 00:45:10.140 2096-2096/? I/Parse: Save Failed
I was having the same issue and initially i though it was the cloud code that needed update. After a lot of troubleshooting I realised that the code was fine. Then I tried to see whether parse server was setup correctly. I am running it on IBM BlueMix (should be the same as heroku). The problem was the following
The server url was resolving to "http0.0.0.0:61026/parse", which was incorrect. I updated it to include :// and the problem was resolved. The new configuration looked like the following:
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || 'mlaburi',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'APPID',
masterKey: process.env.MASTER_KEY || 'MASTER_KEY', //Add your master key here. Keep it secret!,
clientKey:process.env.CLIENT_KEY || 'CLIENT_KEY', //Add you client key here. Keep it secret!,
fileKey:process.env.FILE_KEY || 'FILE_KEY', // Add you file key here,
serverURL: process.env.SERVER_URL || 'https://myappname.herokuapp.com/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
});
Parse.Cloud.define("articles", function(request, response) {
var query = new Parse.Query("Classname");
query.equalTo("name", "rajesh");
query.find({
success: function(results) {
console.log("sucess experts is",results);
response.success(results);
},
error: function(error) {
console.log("error at expert",error);
response.error("expert failed");
}
});
});
It gives following error
ParseError { code: undefined, message: 'unauthorized' }
Error: {"code":141,"message":"failed"}
Activity
gfosco commentedon Feb 11, 2016
Are you requiring/defining
Parsein your cloud code file? This should not be done, as it is a global we mutate during ParseServer initialization.leonardojobim commentedon Feb 11, 2016
No, I am not. The code above is exactly the cloud/main.js file.
gfosco commentedon Feb 11, 2016
Are you setting any client keys in the ParseServer initialization? (rest, js, client, dotnet)... If so, remove them.
leonardojobim commentedon Feb 11, 2016
My settings is according to the Parse Server example:
It is hosted in Heroku and the env vars below are configured.
If I remove the keys (
var api = new ParseServer()), will the server still work and will it be able to be accessed by mobile SDK ???The request to insert a new message (that triggers the beforeSave()) is done by Swift SDK.
simonbengtsson commentedon Feb 11, 2016
I think I have the same problem as @Leo-One. I can't use any queries in cloud code using the parse server as they return with the error
{"code":141,"error":"Error: undefined unauthorized"}.When diving into the source to troubleshoot I saw that all the queries (find, first, get etc) results in
node_modules/parse-server/node_modules/parse/lib/node/RESTController.js:ajax()sending a post request tohttps://api.parse.com/1/classes/MyObjectwhich of course will result inunauthorizedas parse doesn't know anything about my local app. I tried sending a get request to http://localhost:1337/parse/classes/MyObject which works and returns objects as expected.I'm probably missing something here, but what would you have to do to get queries working in cloud code with a local parse server?
simonbengtsson commentedon Feb 12, 2016
What I missed was the serverURL option. Is it the same for you @Leo-One? For me the following works perfectly for local development:
leonardojobim commentedon Feb 12, 2016
@simonbengtsson Just out of curiosity, what is the hosting solution are you using ?
I am using Heroku and I tried:
serverURL: 'https://localhost:1337/parse'orserverURL: 'http://localhost:1337/parse'orserverURL: 'https://localhost:' + port + '/parse'-> received{"code":141,"error":"Error: 100 XMLHttpRequest failed: \"Unable to connect to the Parse API\""}serverURL: 'http://localhost:' + port + '/parse'-> received{"code":141,"error":"Error: undefined unauthorized"}None of above ones worked.
leonardojobim commentedon Feb 12, 2016
I've written the command line:
and it printed
app[web.1]: Parse.serverURL: http://localhost:30835/parsein Heroku as expected.What more could be wrong ?
simonbengtsson commentedon Feb 12, 2016
Im using the parse server locally. The serverurl for heroku would be something like http://your-heroku-app-id.herokuapp.com/parse. Or simply where the parse server is located.
tanmays commentedon Feb 12, 2016
Along with setting the serverURL in index.js make sure you are also passing a valid sessionToken otherwise it will throw an unauthorized error.
jamiechapman commentedon Feb 12, 2016
Also getting a similar response (141 / unauthorised) via Cloud Code. App ID matches client-side and in the
ParseServerconstructor + client keys not defined in client/server. Locally regular CloudCode functions (like the defaulthellofunction in parse-server-example) work just fine, it seems to be queries that have issues. Both all fail when deployed to heroku.client side JS:
=>
cloud/main.js:
(nothing declared outside of
Parse.Cloud.define, Parse not re-imported etc)=>
{"code":141,"error":{"message":"unauthorized"}}simonbengtsson commentedon Feb 12, 2016
What is your initialization code for the parse server @jamiechapman? Make sure you are using the serverURL option there as well.
jamiechapman commentedon Feb 12, 2016
@simonbengtsson
The
serverURLis defined and matches that defined by the client. I have tried fully qualified URL's in the client-side (http://www etc) and a relative path, both produce error 141 for some odd reason!(XXXXXXX's subbed in place of real values, both match server/client side)
jamiechapman commentedon Feb 12, 2016
@simonbengtsson Think I sussed it! The environment variable
APP_IDhad an extra character at the end which likely caused the requests to (rightly) fail. Thanks for the help! 👍45 remaining items
eustache509 commentedon Mar 25, 2016
PLEASE LET ME KNOW HOW I CAN FIX THIS BECAUSE I SPEND 4 DAYS IN IT . I CANT FIX IT
gfosco commentedon Mar 25, 2016
You're explicitly setting the client key to a null value in that code..
Change it to literally any string like 'clientKeyIsNotUsed' and it should
stop telling you that.
On Thursday, March 24, 2016, eustache509 [email protected] wrote:
eustache509 commentedon Mar 25, 2016
Thanks Fosco but it save still fail
eustache509 commentedon Mar 25, 2016
03-24 21:23:40.048 4014-4628/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:40.290 4014-4633/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:41.707 4014-4634/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:44.327 4014-4636/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:49.207 4014-4639/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:58.707 4014-4642/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:34:19.855 4698-4698/? I/Parse: Save Failed
03-24 21:36:16.718 4791-4791/? I/Parse: Save Failed
eustache509 commentedon Mar 25, 2016
@OverRide
public void onCreate() {
super.onCreate();
eustache509 commentedon Mar 25, 2016
03-25 00:44:10.737 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS in package: com.android.shell at: Binary XML file line #101
03-25 00:44:10.787 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.CONFIGURE_WIFI_DISPLAY in package: com.android.systemui at: Binary XML file line #119
03-25 00:44:11.266 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.WRITE_CONTACTS in package: com.android.email at: Binary XML file line #40
03-25 00:44:11.827 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.WAKE_LOCK in package: com.google.android.apps.maps at: Binary XML file line #96
03-25 00:44:12.362 1300-1300/? W/PackageParser: No actions in intent filter at /data/app/ApiDemos/ApiDemos.apk Binary XML file line #3082
03-25 00:44:12.362 1300-1300/? W/PackageParser: No actions in intent filter at /data/app/ApiDemos/ApiDemos.apk Binary XML file line #3088
03-25 00:44:14.607 1300-1300/? W/System.err: at com.android.internal.alsa.AlsaCardsParser.scan(AlsaCardsParser.java:109)
03-25 00:45:10.140 2096-2096/? I/Parse: Save Failed
eustache509 commentedon Mar 25, 2016
it give me different message now but , it still save fail
zirinisp commentedon Sep 8, 2016
I was having the same issue and initially i though it was the cloud code that needed update. After a lot of troubleshooting I realised that the code was fine. Then I tried to see whether parse server was setup correctly. I am running it on IBM BlueMix (should be the same as heroku). The problem was the following
var parseConfig = { databaseURI: databaseUri, appId: process.env.APP_ID, masterKey: process.env.MASTER_KEY, cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', serverURL: ((process.env.HTTPS) ? 'https' : 'http') + host + ':' + port + mountPath, };The server url was resolving to "http0.0.0.0:61026/parse", which was incorrect. I updated it to include :// and the problem was resolved. The new configuration looked like the following:
var parseConfig = { databaseURI: databaseUri, appId: process.env.APP_ID, masterKey: process.env.MASTER_KEY, cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', serverURL: ((process.env.HTTPS) ? 'https://' : 'http://') + host + ':' + port + mountPath, };Such a simple mistake took me 4 hours to resolve.
wellkeptbeauty commentedon May 2, 2017
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || 'mlaburi',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'APPID',
masterKey: process.env.MASTER_KEY || 'MASTER_KEY', //Add your master key here. Keep it secret!,
clientKey:process.env.CLIENT_KEY || 'CLIENT_KEY', //Add you client key here. Keep it secret!,
fileKey:process.env.FILE_KEY || 'FILE_KEY', // Add you file key here,
serverURL: process.env.SERVER_URL || 'https://myappname.herokuapp.com/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
});
Parse.Cloud.define("articles", function(request, response) {
var query = new Parse.Query("Classname");
query.equalTo("name", "rajesh");
query.find({
success: function(results) {
console.log("sucess experts is",results);
response.success(results);
},
error: function(error) {
console.log("error at expert",error);
response.error("expert failed");
}
});
});
It gives following error
ParseError { code: undefined, message: 'unauthorized' }
Error: {"code":141,"message":"failed"}
flovilmart commentedon May 6, 2017
@wellkeptbeauty can you open a new issue with detailed informations? Your issue is most likely an implementation issue and not a Parse-server issue.
dplewis commentedon Jun 16, 2017
@flovilmart I ran into this issue today for some reason.
I used the parse-server-example fresh out of the box added restAPIKey: 'rest' and got error unauthorized using cloud code.
You can fix this by adding javascriptKey: 'unused' or pass in clientKey, dotNetKey, restAPIKey to be undefined.
The issue lies with this line
https://github.com/parse-community/parse-server/blob/master/src/middlewares.js#L19
req.get()is returning undefined but info has some defaultsBRC-solutions commentedon Sep 7, 2017
any solution please
flovilmart commentedon Sep 7, 2017
Did you check @dplewis response?