Skip to content

Passing {useMasterKey: true} to REST api requests in cloud code #3891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AmrKafina opened this issue May 31, 2017 · 6 comments
Closed

Passing {useMasterKey: true} to REST api requests in cloud code #3891

AmrKafina opened this issue May 31, 2017 · 6 comments

Comments

@AmrKafina
Copy link

AmrKafina commented May 31, 2017

I'm writing a cloud code function that calls the /schemas endpoint while processing requests. Since this function requires the masterKey, I thought I'd use Parse.Cloud.httpRequest to make the request, but HTTPOptions doesn't seem to have a useMasterKey property.

How would I go about doing something like this? Hard coding the masterKey in the cloud code function's request headers seems like a bad idea.

@AmrKafina AmrKafina changed the title Passing {useMasterKey: true} to REST api request in cloud code Passing {useMasterKey: true} to REST api requests in cloud code May 31, 2017
@MobileVet
Copy link

Yes, hard coding in the master key is a bad idea... glad you didn't go that route.
Your cloud code can USE the master key without having it passed in by the client making the request, though I have not tried httpRequest as a function that utilizes the master key.

Some examples

query.find({useMasterKey:true});
object.save(null,{useMasterKey:true});
Parse.Object.saveAll(objects,{useMasterKey:true});

@natanrolnik
Copy link
Contributor

You are probably using environment variables to initialize the server, no? If not, you should, instead of hard coding in your index.js.
This way, you can add the master key to the headers of your http request by using process.env.MASTER_KEY or something similar to what you have.

@AmrKafina
Copy link
Author

@natanrolnik ah yes, that's perfect. Thanks!

@flovilmart
Copy link
Contributor

We could also add the useMasterKey option to the Parse.Cloud.httpRequest options ;)

@otmezger
Copy link

There should be a section in the cloud code guide that explains how to use this, just as @MobileVet posted above. With some nice examples :-)

@flovilmart
Copy link
Contributor

Feel free to edit the guides in the docs repo and open a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants