Skip to content

Instantly share code, notes, and snippets.

@joshuamiller
Created March 4, 2010 18:43
Show Gist options
  • 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