我试图建立连接到使用JSforce.js提供的oauth2流销售人员一个Chrome扩展,但所有的例子我在网上找到包含的功能由提供Node.js和Express.js,如何将它们添加到我的应用程序范围,而不需要用户在使用应用程序之前下载它们。任何人都可以向我澄清这个问题,我在这里有点困惑。谢谢!在Chrome拓如何使用Node.js和Express.js
编辑:
我从这里这个例子:link
这是一个使用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);
// ...
});
});
需要(),应用程序。 get(),sf.Oauth2()是由Node.js和Express.js提供的对象/函数,我不能使用
我认为这会有帮助,如果你添加一些这样的例子,或者至少将它们链接起来,如果这些例子很大。 – wOxxOm
@wOxxOm我按照你的建议编辑。顺便说一下,我在每个镀铬扩展柱上总是能看到你。你是一个非常敬业的用户:) –
不是我的专业领域,但我认为应该可以在不使用node.js的情况下使用这些库,即使它不容易(你必须阅读关于应用程序的官方文档并做很多工作实验/谷歌搜索)。 – wOxxOm