我試圖建立連接到使用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