在Chrome扩展中使用Node.js和Express.js
Using Node.js and Express.js in Chrome-Extension
我正试图使用JSforce.js提供的oauth2流构建一个连接到salesforce的chrome扩展,但我在网上找到的所有示例都包含Node.jsExpress.js 编辑: 我从这里得到了这个例子:链接 这是使用express.js框架运行的Oauth2代码: require(),app.get(),sf。Oauth2()是Node.js和Express.js提供的对象/函数,我不能使用 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);
// ...
});
});
Node.js不应该在浏览器或chrome扩展中运行,您应该按照以下说明使用web浏览器设置,并将jsforce.js添加到扩展的页面中。
- 在索引.html和应用.js [node.js] 之间共享变量
- JS(node.js)而循环不起作用
- 如何使用 JS (Node.js) 防止 HTTP 查询中允许使用 UTF8 字符串
- Angular JS & Node Webkit Routing
- 当作为脚本运行时.js Node中“this”的上下文是什么
- JS/Node:- 使用 node.io 选择标记
- JavaScript 如何让节点在返回 node.js/Node-RED 之前等待
- 处理快速连续的函数调用 - Javascript / underscore.js / node.js
- 如何在一台服务器中运行不同的.js文件.js NODE JS中的文件
- JS node-mysql bools 表现得很奇怪
- Node.js+Node Webkit+基于Node串行端口的应用程序-这可能吗
- 如何在Express.js/Node.js中检查查询字符串是否有值
- Express.Js, Node.Js, MongoDB Questions
- 在JS/Node中,当多个人编辑相同的记录时,如何避免数据冲突?有图案吗
- 服务器端js(node.js)上的同步
- 将参数从jade发送到js/node
- angular.js+node.js/electron中的Promise;不起作用
- 是否有可能确定我的应用程序的aws实例使用js/node aws-sdk
- Image Magick模块抛出奇怪的错误(Express js Node js)
- 用JS (Node.js)读取文本文件'