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

org.auth for mode: 'multi' vs. org.oauth for mode: 'single' #123

Closed kterusaki closed 8 years ago

kterusaki commented 8 years ago

Is there any particular reasoning for the different naming convention depending on which mode you are using?

It would convenient if it was one or the other for either mode. I was accessing the instance_url property in the org.auth object, but I switched from multi mode to single mode which threw an error in my code.

kevinohara80 commented 8 years ago

I'm not sure what you mean by org.auth. There is never a property called org.auth. org.oauth is the property used to store internal oauth credentials for single user mode.

Connection properties: https://github.com/kevinohara80/nforce/blob/master/index.js#L41

The instance_url error that you are experiencing is usually caused from missing oauth credentials. In single user mode, when you call authenticate() and the auth succeeds, the oauth information is automatically stored internally. If you are creating a new connection object but already have oauth credentials that you want to use, you need to set them with the setOAuth() method like so...

var org = nforce.createConnection({
  mode: 'single',
  ...
});

org.setOAuth(myoauth);

You can also set it as a property in the createConnection options...

var org = nforce.createConnection({
  mode: 'single',
  oauth: myoauth
  ...
});

More on the OAuth object: https://github.com/kevinohara80/nforce#oauth-object

Let me know if that makes sense.