简体   繁体   English

关于为什么我无法在jsforce auth函数中使用heroku环境变量的任何线索?

[英]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. 因此,我属于为我们的客户开发网络应用程序的团队的一部分,该客户使用Salesforce作为他们的数据库。 We are using node.js on heroku to act for the server side code. 我们在heroku上使用node.js来充当服务器端代码。 The front end is angular, but it's irrelevant to my issue. 前端是有角度的,但与我的问题无关。 We are using the jsforce framework to connect to our salesforce app. 我们正在使用jsforce框架连接到我们的salesforce应用程序。 The client secret and client id are stored as environment variables in heroku, and locally!! 客户机密和客户ID作为环境变量存储在heroku和本地中! When I dummy test the auth function with the key and Id as just strings, I have success. 当我用键和Id作为字符串虚拟测试auth函数时,我就成功了。 However, any attempt to anything other than hardcode, I run into issues with the variables not being defined. 但是,除了硬编码以外的任何尝试,都会遇到未定义变量的问题。 Here's the app.js code. 这是app.js代码。

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. 在heroku中,如果您导航到设置,则有一个选项卡显示配置变量。

Add the required variables in there. 在其中添加所需的变量。

For example the key would be SALESFORCE_USERNAME 例如,密钥为SALESFORCE_USERNAME

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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