Created
October 12, 2012 01:54
-
-
Save dboundz/3876911 to your computer and use it in GitHub Desktop.
Express Github OAuth2 flow
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
exports.github = function (req, res) { | |
res.redirect(config.Github.API_ROOT + config.Github.PATH_AUTHENTICATE + '?client_id=' + config.Github.CLIENT_ID); | |
}; | |
exports.githubCallback = function (req, res) { | |
var code = req.query.code; | |
var post_data = querystring.stringify({ | |
code: code | |
, client_id: config.Github.CLIENT_ID | |
, client_secret: config.Github.CONSUMER_SECRET | |
}); | |
var post_headers = { | |
'Content-Type': 'application/x-www-form-urlencoded' | |
, 'Content-Length': post_data.length | |
}; | |
var post_options = { | |
host: config.Github.HOSTNAME | |
, port: 443 | |
, path: config.Github.PATH_ACCESS_TOKEN | |
, method: 'POST' | |
, headers: post_headers | |
}; | |
var post_req = https.request(post_options, function(res) { | |
res.setEncoding('utf8'); | |
res.on('data', function (chunk) { | |
console.log('Response: ' + chunk); | |
}); | |
}); | |
post_req.write(post_data); | |
post_req.end(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment