Created
July 16, 2014 19:01
-
-
Save redryan/4b0fe6f0e7b12123dcba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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