简体   繁体   中英

Any clue as to why I am not able to use heroku environment variables in my jsforce auth function?

So I'm part of a team working on developing an a web app for our client, who uses salesforce as their database. We are using node.js on heroku to act for the server side code. The front end is angular, but it's irrelevant to my issue. We are using the jsforce framework to connect to our salesforce app. The client secret and client id are stored as environment variables in heroku, and locally!! When I dummy test the auth function with the key and Id as just strings, I have success. However, any attempt to anything other than hardcode, I run into issues with the variables not being defined. Here's the app.js code.

var express = require('express');
var app = express();
var jsforce = require('jsforce');
//var conn = new jsforce.Connection();
//var username = process.env.SALESFORCE_USERNAME;
//var password = process.env.SALESFORCE_PASSWORD;
var consumersecret = process.env.SALESFORCE_CONSUMERSECRET;
var consumerkey = process.env.SALESFORCE_CONSUMERKEY;

console.log();

app.set('port', (process.env.PORT || 5000));

app.use(express.static(__dirname + '/public'));

// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');


app.get('/', function(request, response) {
response.render('pages/index');
});

var oauth2 = new jsforce.OAuth2({
    clientId : consumerkey,
    clientSecret : consumersecret,
    redirectUri : 'https://ap1.salesforce.com/services/oauth2/token'
});


 app.get('/oauth/callback', function(req, res) {
    res.redirect(oauth2.getAuthorizationUrl({scope :'api id web'}));
 });


app.listen(app.get('port'), function() {
console.log('Node app is running on //port', app.get('port'));
});

Any help or suggestions would be super appreciated! Thank you!

In heroku if you navigate to settings there's a tab that reveals the config variables.

Add the required variables in there.

For example the key would be SALESFORCE_USERNAME

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM