I'm currently experimenting with Parse Cloud Functions.
The following simple example already worked well:
Parse.Cloud.define("hello", async (request) => {
return "Hi " + request.params.name;
});
In my apps I login as a user before making any request so I want to restrict access to this function by objectId of the user.
The docs give the following example for validation:
requireUserKeys: {
accType : {
options: 'reviewer',
error: 'Only reviewers can get average stars'
}
}
So I added this validation to my request (and I require masterKey for validation as normal users are not allowed to read User objects):
Parse.Cloud.define("hello", async (request) => {
return "Hi " + request.params.name;
}, {
validateMasterKey: true,
requireUserKeys: {
objectId: {
options: "ABCD1234", // dummy id
error: "Unauthorized"
}
}
});
If I now make a request as the logged in user with the objectId "ABCD1234" I get the error message "Unauthorized", so the validation does not work as intended.
How do you implement user restriction correctly for Cloud functions? Thanks for you help.

Since you added the
validateMasterKey: trueoption, the cloud code function will run only when passing the master key, regardless of the logged in user. In fact, you should either usevalidateMasterKeyoption orrequireUserKeysoption. It does not make sense to use both of them at the same time.