What is the secure way to access a user's session token from Parse Cloud Code functions with a self hosted Node.js server?
My cloud code function looks like this:
PFCloud.callFunctionInBackground("checkUser", withParameters: nil) {
(response: AnyObject?, error: NSError?) -> Void in
let responseString = response as? String
print(responseString)
}
And I'd like to be able to do something like this:
Parse.Cloud.define("checkUser", function(request, response) {
var sessionToken = request.user.getSessionToken();
response.success(sessionToken);
});
However my request.user returns nil.
Is it safe to pass the session token as a parameter
let sessionToken = currentUser!.sessionToken
PFCloud.callFunctionInBackground("checkUser", withParameters: ["sessionToken": sessionToken!]) {
(response: AnyObject?, error: NSError?) -> Void in
let responseString = response as? String
print(responseString)
}
Edit
I found something of use here: https://parse.com/tutorials/session-migration-tutorial
and it shows that I should be able to make it a header to the request:
curl -X POST \
-H "X-Parse-Application-Id: <YOUR_APPLICATION_ID>" \
-H "X-Parse-REST-API-Key: <YOUR_REST_API_KEY>" \
-H "X-Parse-Session-Token: <CURRENT_LEGACY_SESSION_TOKEN>" \
https://api.parse.com/1/upgradeToRevocableSession
but I'm not sure where these headers are set in the swift backend.