Created
February 3, 2016 20:18
-
-
Save joshbirk/9f1f5298710b68aef725 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
app.post('/token',function (req, res) { | |
console.log(req.body); | |
var sr = sync_request('POST', 'https://login.salesforce.com/services/oauth2/token', | |
{ | |
headers: {'Content-Type':'application/x-www-form-urlencoded','Accept':'application/json'}, | |
body: 'grant_type='+req.body.grant_type+'&code='+req.body.code+'&refresh_token='+req.body.refresh_token+'&client_id='+req.body.client_id+'&client_secret='+req.body.client_secret+'&redirect_uri='+req.body.redirect_uri | |
}); | |
console.log(sr.getBody('utf8')); | |
response = JSON.parse(sr.getBody('utf8')); | |
response.access_token = response.access_token + " " + response.instance_url; | |
response.expires_in = 5400; //in seconds, set this to be less than your setting under session management. | |
res.jsonp(response); | |
}); |
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
/*how to then grab the instance url from Amazon. */ | |
function route_alexa_intent(req, res) { | |
if(req.body == null) { | |
return res.jsonp({message: 'no post body found'}); | |
} | |
if(req.body.session == null || req.body.session.user == null || req.body.session.user.accessToken == null) { | |
send_alexa_response(res, 'Please log into Salesforce', 'Salesforce', 'Not Logged In', 'Error: Not Logged In', true); | |
} | |
oauth = {access_token : req.body.session.user.accessToken.split(" ")[0], | |
instance_url : req.body.session.user.accessToken.split(" ")[1]} | |
//now use oauth to make requests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment