node-parse-api icon indicating copy to clipboard operation
node-parse-api copied to clipboard

Add sessionToken as constructor option

Open achimkoellner opened this issue 10 years ago • 0 comments

I'd love to use node-parse-api with a logged-in user. The node server receives a sessionToken from the client and performs database operations on behalf of that session. For that purpose the session_token (besides app_key and api_key) can be passed to the constructor.

If no sessionToken is passed to the parseRequest method by argument, the method checks if the constructor options contain a session_token value and sends an X-Parse-Session-Token header with the request.

This allows e.g. to find objects of classes that are restricted to be read by only that user (or role).

// example usage
var Parse = require('node-parse-api').Parse;

// let's assume this is a sessionToken of an user who is member of the role "moderator"
var sessionToken = '3h3gaa32bdd3h3gaa323h3gaa32bddbdd';

var options = {
    app_id:'...',
    api_key:'...',
    session_token: sessionToken // , master_key:'...' could be used too 
}

var app = new Parse(options);

// let's assume Foo is a class with read permission for "moderator"-users only
app.find('Foo', {objectId: 'someId'}, function (err, response) {
    console.log(response);
});

achimkoellner avatar Dec 19 '15 07:12 achimkoellner