question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NForce Connection Issue

See original GitHub issue

I’m having issues connecting to Salesforce through my app. My goal is to create an account for the user when a button is clicked, and that the account is created by automatically logging into Salesforce using my own username/password/security token. My app is written in javascript/html/css and was created using Meteor. Here is the relevant code (all capitalized variables I have hardcoded with actual values):

case "SalesForceButton":
    var nforce = require('nforce');

    var org = nforce.createConnection({
        clientId: 'CLIENT_ID',
        clientSecret: 'CLIENT_SECRET',
        redirectUri: 'https://localhost:3000/oauth/_callback',
        environment: 'production',
        mode: 'single'
    });
    var username      = 'USERNAME',
    password      = 'PASSWORD',
    securityToken = 'SECURITY_TOKEN',
    oauth;

    org.authenticate({ username: username, password: password, securityToken: securityToken }, 
    function(err, resp){
        if(!err) {
            console.log('Access Token: ' + resp.access_token);
            oauth = resp;

            var acc = nforce.createSObject('Account');
            acc.set('Name', 'Spiffy Cleaners');
            acc.set('Phone', '800-555-2345');
            org.insert({sobject: acc}, function(err, resp){
                if(!err) console.log('It worked!');
            });
        } else {
            console.log('Error: ' + err.message);
        }

    });
break;

Things I’ve done:

  1. Setup nforce properly (npm install nforce)
  2. Created a connected app on Salesforce using the same redirect URI as above and https://localhost:3000 as the start URL
  3. Whitelisted https://localhost:3000 in the CORS section in Salesforce
  4. Put https://localhost:3000 in Remote Site Settings section in Salesforce
  5. Done all the steps above but using a publicly hosted URL (https://www.my_company.com)
  6. Used the “Access-Control-Allow-Origin” chrome extension (it shortened the second error below but console was still showing “Response to preflight request doesn’t pass access control check: Response had HTTP status code 400.”

Errors I’m getting: screen shot 2018-07-31 at 12 51 09 pm

Any help would be greatly appreciated. I can provide more information if needed. Thank you!!!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
amazingjoecommented, Aug 2, 2018

I think you might have just hit a F-cked up SF technical brick wall.

Take a look at the last post in this thread.

https://developer.salesforce.com/forums/?id=9060G000000XfhRQAS

Essentially you can set up your instance to whitelist the different domains etc… but the authentication server is not your server and not under your purview to whitelist on behalf of. Which sucks.

It looks like even people using Lighting Out (Salesforce Lighting Components served outside of Salesforce in Javascript) have to find a means around this to get a token.

Here is an example of one proxy that does so. I am betting there are probably prebuilt one button Heroku proxies you can find that will authenticate for you and return the token.

This link has some information on how to get authenticated but it involves setting up nodejs etc… to do so. http://cloudyworlds.blogspot.com/2016/03/taking-your-lightning-components.html

So essentially it looks like you need to use a proxy to get your tokens and leverage CORS to avoid using a proxy.

https://stackoverflow.com/questions/29670703/how-to-use-cors-anywhere-to-reverse-proxy-and-add-cors-headers

Now since you probably don’t want to do all that work I think you could leverage a CORS Proxy to perform the authentication and get your token and then after that you should be good to go hopefully. You will need to set up the authentication for the remote app and whitelists for the proxy server I am thinking.

0reactions
kevinohara80commented, Nov 1, 2018

Going to close this since there doesn’t seem to be an nforce issue. Please re-open if I’m wrong 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

NFOrce Internet Services - Support
If you have issues with your dedicated server, or virtual service provided by NFOrce Entertainment B.V. we ask of you to provide us...
Read more >
NVIDIA nForce network controller causes a ... - Microsoft Support
When you use an NVIDIA nForce network controller in a Windows 7-based computer, you may lose the network connection intermittently.
Read more >
Node.js nforce connection error with Slack client Id
I am in the process of creating a Slack-Salesforce chat bot, and I am currently using node.js and nforce to achieve this.
Read more >
Error when trying to Update using nforce to Product2 object
... to authenticate to the org using org.authenticate nforce function. Does this user have access to the external ID field? – arut. Aug...
Read more >
Salesforce Web Application Using nForce - MST Solutions
We can connect Node.js web application with Salesforce using nForce and ... port); }); // LEAD API ROUTES BELOW // Generic error handler...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found