Skip to content
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

Added req.auth.user to parse cloud functions #172

Merged
merged 2 commits into from
Feb 2, 2016

Conversation

taylorstine
Copy link
Contributor

According to the TODO here the cloud code functions are missing the req.user parameter. Here, I'm adding the parameter based on the req.auth. Note that in order to get this to work, I had to overwrite the session token returned from the user query with the one provided in req.info. Please scrutnize this closely, I have no idea why the _User object is even stored with a session token. When I try to use the session token returned from the user query, my cloud functions return empty results because I have ACL permissions set up. I did delete some of my session tokens earlier, so that might have something to do with it.

If this update is incorrect, maybe an error should be thrown if there is an invalid session token. If the _User object is stored with a session token in order to provide some kind of master validation for any requests that user might make, and that session token was removed from the database of session tokens, then there is no error thrown, and to the user it just looks like no results are showing from their query.

Please advise, again I do not fully know the implications of doing this.

@xwizi
Copy link

xwizi commented Feb 2, 2016

I need this update as I too have the same problem my cloud functions do not get a user - How can i add this to my local version - it seems the library is not installed as I would expect - where are the files in the demo app.

@taylorstine
Copy link
Contributor Author

@xwizi you could clone my repo and then use npm link to use your local parse-server rather than the one installed from npm.
so:

git clone git@github.com:taylorstine/parse-server.git
git checkout -b cloud_shim origin/cloud_shim
cd ~/The/Directory/For/Your/App
npm link ../The/Directory/For/The/Clone

@@ -13,7 +13,8 @@ function handleCloudFunction(req) {
return new Promise(function (resolve, reject) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the TODO from line 11?

@taylorstine
Copy link
Contributor Author

@gfosco updated

@xwizi
Copy link

xwizi commented Feb 2, 2016

@taylorstine Gotcha I actually tried modifying my local copy, not so smart :-( - i'll try as you say hopefully that will fix my issues

@xwizi
Copy link

xwizi commented Feb 2, 2016

@taylorstine saying permission denied public key -

git clone git@github.com:taylorstine/parse-server.git
Cloning into 'parse-server'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

@xwizi
Copy link

xwizi commented Feb 2, 2016

@taylorstine : Ignore that

@taylorstine
Copy link
Contributor Author

@xwizi 😜

gfosco added a commit that referenced this pull request Feb 2, 2016
Added req.auth.user to parse cloud functions
@gfosco gfosco merged commit a78adfe into parse-community:master Feb 2, 2016
@gfosco
Copy link
Contributor

gfosco commented Feb 2, 2016

👍

@xwizi
Copy link

xwizi commented Feb 2, 2016

@gfosco @taylorstine Looks like this is now committed thanks for everyone's help!

@natanrolnik
Copy link
Contributor

@taylorstine is request.user returning the authenticated user in your Cloud Code functions? I've updated parse-server to 2.0.5 and request.user is still undefined here 😭

@taylorstine
Copy link
Contributor Author

@natanrolnik That's actually my bad 😞 , I forgot that there is a master option that is set to true in the req.master parameter. Also, the spec for the cloud code functions says that the req.user object will be undefined, and I've set it to an empty object, which is likely causing an error when you call req.user.getSessionToken(). I'm assuming your problems are occurring because of this, and because you are using the master key. See #209

@natanrolnik
Copy link
Contributor

@taylorstine thanks for the answer. Ok - so is there any changes I should do on my server initialization, or should I wait for #209 to be merged?

@taylorstine
Copy link
Contributor Author

@natanrolnik I can't be sure without seeing your code, but I'm assuming that you won't need any changes to your server initialization. You can always pull down my branch and test it with your server. I was able to reproduce your issue if I used a master key.

jeveloper added a commit to jeveloper/parse-server that referenced this pull request May 6, 2017
Updated mongodb-core to 2.1.10
NODE-981 delegate auth to replset/mongos if inTopology is set.
NODE-978 Wrap connection.end in try/catch for node 0.10.x issue causing exceptions to be thrown, Also surfaced getConnection for mongos and replset.
Remove dynamic require (Issue parse-community#175, https://github.com/tellnes).
NODE-696 Handle interrupted error for createIndexes.
Fixed isse when user is executing find command using Server.command and it get interpreted as a wire protcol message, parse-community#172.
NODE-966 promoteValues not being promoted correctly to getMore.
Merged in fix for flushing out monitoring operations.
NODE-983 Add cursorId to aggregate and listCollections commands (Issue, parse-community#1510).
Mark group and profilingInfo as deprecated methods
NODE-956 DOCS Examples.
Update readable-stream to version 2.2.7.
NODE-978 Added test case to uncover connection.end issue for node 0.10.x.
NODE-972 Fix(db): don't remove database name if collectionName == dbName (Issue, parse-community#1502)
Fixed merging of writeConcerns on db.collection method.
NODE-970 mix in readPreference for strict mode listCollections callback.
NODE-966 added testcase for promoteValues being applied to getMore commands.
NODE-962 Merge in ignoreUndefined from collection level for find/findOne.
Remove multi option from updateMany tests/docs (Issue parse-community#1499, https://github.com/spratt).
NODE-963 Correctly handle cursor.count when using APM.
flovilmart pushed a commit that referenced this pull request May 6, 2017
Updated mongodb-core to 2.1.10
NODE-981 delegate auth to replset/mongos if inTopology is set.
NODE-978 Wrap connection.end in try/catch for node 0.10.x issue causing exceptions to be thrown, Also surfaced getConnection for mongos and replset.
Remove dynamic require (Issue #175, https://github.com/tellnes).
NODE-696 Handle interrupted error for createIndexes.
Fixed isse when user is executing find command using Server.command and it get interpreted as a wire protcol message, #172.
NODE-966 promoteValues not being promoted correctly to getMore.
Merged in fix for flushing out monitoring operations.
NODE-983 Add cursorId to aggregate and listCollections commands (Issue, #1510).
Mark group and profilingInfo as deprecated methods
NODE-956 DOCS Examples.
Update readable-stream to version 2.2.7.
NODE-978 Added test case to uncover connection.end issue for node 0.10.x.
NODE-972 Fix(db): don't remove database name if collectionName == dbName (Issue, #1502)
Fixed merging of writeConcerns on db.collection method.
NODE-970 mix in readPreference for strict mode listCollections callback.
NODE-966 added testcase for promoteValues being applied to getMore commands.
NODE-962 Merge in ignoreUndefined from collection level for find/findOne.
Remove multi option from updateMany tests/docs (Issue #1499, https://github.com/spratt).
NODE-963 Correctly handle cursor.count when using APM.
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

Successfully merging this pull request may close these issues.

None yet

4 participants