简体   繁体   中英

Using Node.js and Express.js in Chrome-Extension

I am trying to build a chrome extension that connects to salesforce using oauth2 flow provided by JSforce.js but all the examples I found online contain functionality provided by Node.js and Express.js , how can I add them to my application scope, without requiring the user to download them before using the application. Can anyone clarify this issue to me, I am getting a bit confused here. Thanks!

EDIT:

I got this example from here : link

This is the Oauth2 code that uses express.js framework to run:

 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() are objects/functions provided by Node.js and Express.js which I cannot use

Node.js并非要在浏览器或chrome扩展程序中运行,您应该按照以下说明使用网络浏览器设置,并将jsforce.js添加到扩展程序页面中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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