Created
December 18, 2012 08:12
-
-
Save anonymous/4326062 to your computer and use it in GitHub Desktop.
twitter oauth login with acitonHero
This file contains hidden or 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
var oauth = require('oauth'); | |
var consumerKey = "AAA"; | |
var consumerSecret = "BBB"; | |
var callbackURL = "http://127.0.0.1:8080/twitterOauthCatch"; // be sure to set me in the application's settings | |
// http://127.0.0.1:8080/twitterOauthStart | |
var oathClient = new oauth.OAuth( | |
"https://twitter.com/oauth/request_token", | |
"https://twitter.com/oauth/access_token", | |
consumerKey, | |
consumerSecret, | |
"1.0A", | |
callbackURL, | |
"HMAC-SHA1" | |
); | |
exports.twitterOauthStart = { | |
name: "twitterOauthStart", | |
description: "I start the oauthProcess", | |
inputs: { required: [], optional: [] }, | |
outputExample: { randomNumber: 123 }, | |
run:function(api, connection, next){ | |
oathClient.getOAuthRequestToken(function(error, oauthToken, oauthTokenSecret, results){ | |
if(error){ | |
connection.error = error.data; | |
api.log(error.data, "red") | |
next(connection, true) | |
}else{ | |
api.cache.save(api, "oauth_" + connection.id , {oauthToken: oauthToken, oauthTokenSecret: oauthTokenSecret}, 1000 * 60 * 5, function(err){ | |
connection.response.redirectURL = "https://twitter.com/oauth/authorize?oauth_token="+oauthToken; | |
connection.responseHeaders.push(['Location', connection.response.redirectURL]); | |
connection.responseHttpCode = 302; | |
next(connection, true); | |
}); | |
} | |
}); | |
} | |
} | |
exports.twitterOauthCatch = { | |
name: "twitterOauthCatch", | |
description: "I catch the user when they come back from the oAuth provider", | |
inputs: { required: ["oauth_token", "oauth_verifier"], optional: [] }, | |
outputExample: { randomNumber: 123 }, | |
run:function(api, connection, next){ | |
api.cache.load(api, "oauth_" + connection.id, function(err, savedOauthDetails){ | |
oathClient.getOAuthAccessToken( | |
savedOauthDetails.oauthToken, | |
savedOauthDetails.oauthTokenSecret, | |
connection.params.oauth_verifier, | |
function(error, oauth_access_token, oauth_access_token_secret, results){ | |
if (error){ | |
connection.error = error.data; | |
api.log(error.data, "red") | |
next(connection, true); | |
} else { | |
connection.response.twitterDetails = results; | |
next(connection, true); | |
} | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment