Skip to content

Instantly share code, notes, and snippets.

@sdurandeu
Created September 16, 2013 03:48
Show Gist options
  • Save sdurandeu/6576538 to your computer and use it in GitHub Desktop.
Save sdurandeu/6576538 to your computer and use it in GitHub Desktop.
OAuth Request Token (HTTPS POST Request)
// An object of options to indicate where to post to
var post_options = {
host: 'api.mercadolibre.com',
port: '443',
path: util.format("/oauth/token?grant_type=authorization_code&client_id=%s&client_secret=%s&code=%s&redirect_uri=" + callbackUri,
config.clientId, config.clientSecret, encodeURIComponent(code)),
secureProtocol: 'SSLv3_method',
agent: false,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': 0
}
};
// Set up the request
var post_req = https.request(post_options, function(response) {
response.on('data', function (chunk) {
console.log('Response: ' + chunk);
res.send('Response: ' + chunk);
});
});
post_req.on('error', function(e) {
console.error(e);
});
// post the data
post_req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment