Created
March 4, 2010 18:43
-
-
Save joshuamiller/322007 to your computer and use it in GitHub Desktop.
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
module XAuth | |
module_function | |
def retrieve_access_token(username, password, consumer_key, consumer_secret, site = 'https://api.twitter.com') | |
consumer = OAuth::Consumer.new( | |
consumer_key, | |
consumer_secret, | |
:site => site | |
) | |
# The code below is helped by: | |
# http://ja.pastebin.ca/1796209 | |
# http://gist.github.com/259989 | |
access_token = consumer.get_access_token(nil, {}, { | |
:x_auth_mode => "client_auth", | |
:x_auth_username => username, | |
:x_auth_password => password, | |
}) | |
[consumer, access_token] | |
end | |
end | |
namespace :channels do | |
desc "Convert password-auth accounts to oauth with xauth" | |
task :xauth => :environment do | |
Channel.all(:conditions => { :oauth_enabled => false }).each do |channel| | |
token, secret = XAuth.retrieve_access_token(channel.username, | |
channel.password, | |
Configuration.oauth_consumer_key, | |
Configuration.oauth_consumer_secret) | |
channel.update_attributes(:oauth_token => token, | |
:oauth_secret => secret, | |
:oauth_enabled => true, | |
:password => 'xxxxxxoauthxxxxxxx') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment