Forked from anonymous/twitterOauthActionhero.js
Last active
December 9, 2015 20:48
-
-
Save evantahler/4326070 to your computer and use it in GitHub Desktop.
update for actionHero 6.x
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 = "AAAAAAAAAAAAAAAAAA"; | |
var consumerSecret = "BBBBBBBBBBBBBBBBBBBB"; | |
var callbackURL = "http://127.0.0.1:8080/twitterOauthCatch"; // be sure to set me in the application's settings on dev.twitter.com | |
var oathClient = new oauth.OAuth( | |
"https://twitter.com/oauth/request_token", | |
"https://twitter.com/oauth/access_token", | |
consumerKey, | |
consumerSecret, | |
"1.0A", | |
callbackURL, | |
"HMAC-SHA1" | |
); | |
// http://127.0.0.1:8080/twitterOauthStart | |
exports.twitterOauthStart = { | |
name: "twitterOauthStart", | |
description: "I start the oauthProcess", | |
inputs: { required: [], optional: [] }, | |
outputExample: {}, | |
run:function(api, connection, next){ | |
oathClient.getOAuthRequestToken(function(error, oauthToken, oauthTokenSecret, results){ | |
if(error){ | |
connection.error = error.data; | |
api.log(error.data, "error") | |
next(connection, true) | |
}else{ | |
api.cache.save("oauth_" + connection.id , {oauthToken: oauthToken, oauthTokenSecret: oauthTokenSecret}, 1000 * 60 * 5, function(err){ | |
connection.response.redirectURL = "https://twitter.com/oauth/authorize?oauth_token="+oauthToken; | |
connection.rawConnection.responseHeaders.push(['Location', connection.response.redirectURL]); | |
connection.rawConnection.responseHttpCode = 302; | |
next(connection, true); | |
}); | |
} | |
}); | |
} | |
} | |
// http://127.0.0.1:8080/twitterOauthCatch | |
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: {}, | |
run:function(api, connection, next){ | |
api.cache.load("oauth_" + connection.id, function(err, savedOauthDetails){ | |
if(err != null){ | |
connection.error = error; | |
api.log(error.data, "error") | |
next(connection, true); | |
}else{ | |
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, "error") | |
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