Skip to content

Instantly share code, notes, and snippets.

@joshuamiller
Created March 4, 2010 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuamiller/322007 to your computer and use it in GitHub Desktop.
Save joshuamiller/322007 to your computer and use it in GitHub Desktop.
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