Created
September 16, 2013 03:48
-
-
Save sdurandeu/6576538 to your computer and use it in GitHub Desktop.
OAuth Request Token (HTTPS POST Request)
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
// 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