Reputation: 639
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
Upvotes: 1
Views: 4878
Reputation: 4398
Node.js is not meant to be run on the browser or in a chrome extension, you should use the web-browser setup following these instructions and adding jsforce.js to your extension's page.
Upvotes: 2