Skip to content

Instantly share code, notes, and snippets.

@redryan
Created July 16, 2014 19:01
Show Gist options
  • Save redryan/4b0fe6f0e7b12123dcba to your computer and use it in GitHub Desktop.
Save redryan/4b0fe6f0e7b12123dcba to your computer and use it in GitHub Desktop.
/* SF OAuth request, redirect to SF login */
app.get('/oauth/auth', function(req, res) {
res.redirect(oauth2.getAuthorizationUrl({scope: 'api id web'}));
});
/* OAuth callback from SF, pass received auth code and get access token */
app.get('/oauth/callback', function(req, res) {
var conn = new jsforce.Connection({oauth2: oauth2});
var code = req.query.code;
conn.authorize(code, function(err, userInfo) {
if (err) { return console.error(err); }
console.log('Access Token: ' + conn.accessToken);
console.log('Instance URL: ' + conn.instanceUrl);
console.log('User ID: ' + userInfo.id);
console.log('Org ID: ' + userInfo.organizationId);
req.session.accessToken = conn.accessToken;
req.session.instanceUrl = conn.instanceUrl;
res.redirect('/accounts');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment