Permalink
Browse files

Complete twitter authorize flow.

  • Loading branch information...
1 parent 77c8086 commit 990109ff9b2e51d507e338029a5cdd4c85f38e9d @llun committed Feb 24, 2013
Showing with 25 additions and 1 deletion.
  1. +25 −1 services/twitter.js
View
26 services/twitter.js
@@ -18,8 +18,32 @@ var Twitter = function (key, secret, url) {
'HMAC-SHA1');
}
-Twitter.prototype.authorizeUrl = function () {
+Twitter.secrets = {};
+Twitter.prototype.authorize = function (req, res) {
+ this.oauth.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, oauth_authorize_url, additionalParameters ) {
+ if(error) {
+ console.err( 'Error retrieving the OAuth Request Token: ' + JSON.stringify(error) );
+ res.redirect('/admin'); // Ignore the error upstream, treat as validation failure.
+ } else {
+ console.log ( 'Successfully retrieved the OAuth Request Token' );
+ Twitter.secrets[oauth_token] = oauth_token_secret;
+ res.redirect('http://twitter.com/oauth/authenticate?oauth_token=' + oauth_token);
+ }
+ });
+}
+
+Twitter.prototype.callback = function (req, cb) {
+ this.oauth.getOAuthAccessToken(req.query.oauth_token,
+ Twitter.secrets[req.query.oauth_token], req.query.oauth_verifier,
+ function (err, token, secret, user) {
+ if (err) {
+ cb(err);
+ }
+ else {
+ cb(null, token + '|' + secret);
+ }
+ });
}
module.exports = Twitter;

0 comments on commit 990109f

Please sign in to comment.