kevinohara80 / nforce

nforce is a node.js salesforce REST API wrapper for force.com, database.com, and salesforce.com
MIT License
474 stars 167 forks source link

Auth variable #92

Closed kterusaki closed 9 years ago

kterusaki commented 9 years ago

I noticed in your documentation that you don't pass in the auth variable when querying Salesforce. However, when I do this I get an error:

opts.oauth.instance_url,
                ^
TypeError: Cannot read property 'instance_url' of undefined

This makes sense since you always need to pass in the access token to retrieve any information from Salesforce (at least that's my understanding of the rest api). Thus, I thought maybe you just have to set the res in the authenticate method callback to org.oauth and the DML methods for org would reference that variable when making REST calls to Salesforce like below:

var org = nforce.createConnection(sf_creds);
org.authenticate({ username: 'my_username', password: 'my_pw' }, 
  function(err, res) {
    if (!err) {
      org.oauth = res;
      org.query({ query: 'SELECT Id, Name FROM User LIMIT 1' }, 
        function(err, res) {
          if (err) {
            console.log('query error: ' + err);
          } else {
            console.log('query success: ' + res);
          }
        }
      );
    } else {
      console.log('Salesforce oauth error: ' + err);
    }

However, when running the above code, I get the same error. If you're always supposed to pass in the auth object on any REST calls, what's the point of having the auth key in the org object? Why not set the auth object to the auth key in the org object and have the REST calls reference it from the org object?

michacom commented 9 years ago

The nforce supports multi and single modes. In the single mode you have not to provide OAuth to queries, but you have to createConnection with { mode: 'single' } option.

See Usage section.

kterusaki commented 9 years ago

@michacom Got it, I didn't quite understand the use of multi and single modes, but not it makes sense. Thank you!

kevinohara80 commented 9 years ago

Thanks @michacom