在Chrome扩展中使用Node.js和Express.js

我正在尝试构build一个chrome扩展,它使用JSforce.js提供的oauth2stream连接到salesforce ,但是我在线上find的所有示例都包含由Node.jsExpress.js提供的function,如何将它们添加到我的应用程序范围要求用户在使用应用程序之前下载它们。 任何人都可以澄清这个问题,我在这里有点困惑。 谢谢!

编辑:

我从这里得到这个例子: 链接

这是使用express.js框架运行的Oauth2代码:

var jsforce = require('jsforce'); // // OAuth2 client information can be shared with multiple connections. // var oauth2 = new sf.OAuth2({ // you can change loginUrl to connect to sandbox or prerelease env. // loginUrl : 'https://test.salesforce.com', clientId : '<your Salesforce OAuth2 client ID is here>', clientSecret : '<your Salesforce OAuth2 client secret is here>', redirectUri : '<callback URI is here>' }); // // Get authz url and redirect to it. // app.get('/oauth2/auth', function(req, res) { res.redirect(oauth2.getAuthorizationUrl({ scope : 'api id web' })); }); // Pass received authz code and get access token // app.get('/oauth2/callback', function(req, res) { var conn = new sf.Connection({ oauth2 : oauth2 }); var code = req.param('code'); conn.authorize(code, function(err, userInfo) { if (err) { return console.error(err); } // Now you can get the access token, refresh token, and instance URL information. // Save them to establish connection next time. console.log(conn.accessToken); console.log(conn.refreshToken); console.log(conn.instanceUrl); console.log("User ID: " + userInfo.id); console.log("Org ID: " + userInfo.organizationId); // ... }); }); 

require(),app.get(),sf.Oauth2()是Node.js和Express.js提供的对象/函数,我不能使用它

Node.js并不是要在浏览器上运行,或者在Chrome扩展中运行,您应该按照这些说明使用Web浏览器设置,并将jsforce.js添加到您的扩展页面。