From 3b103713c0f725a598e7f45c3e25671c03f3b421 Mon Sep 17 00:00:00 2001 From: Jason Toy Date: Thu, 16 Sep 2010 09:19:08 -0700 Subject: [PATCH 1/4] works with mongoid now --- lib/devise/twitter/warden.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/devise/twitter/warden.rb b/lib/devise/twitter/warden.rb index 8f6065e..726b4b9 100644 --- a/lib/devise/twitter/warden.rb +++ b/lib/devise/twitter/warden.rb @@ -5,13 +5,13 @@ if perform_connect # Add twitter_handle to current user - already_existing_user = klass.find_by_twitter_handle(twitter_handle) + already_existing_user = klass.first(:twitter_handle => twitter_handle) if already_existing_user.blank? # We don't know anyone with this handle, therefore continue with connecting user = @env['warden'].user - user.twitter_handle = twitter_handle - user.twitter_oauth_token = access_token.token - user.twitter_oauth_secret = access_token.secret + user.login = twitter_handle + user.token = access_token.token + user.secret = access_token.secret user.save return user else @@ -23,7 +23,7 @@ previous_user = @env['warden'].user # Try to find user by token - user = klass.find_by_twitter_oauth_token_and_twitter_oauth_secret(access_token.token, access_token.secret) + user = klass.first(:token=> access_token.token, :secret => access_token.secret) # Since we are logging in a new user we want to make sure the before_logout hook is called @env['warden'].logout if previous_user.present? @@ -31,9 +31,9 @@ if user.nil? # Create user if we don't know him yet user = klass.new - user.twitter_handle = twitter_handle - user.twitter_oauth_token = access_token.token - user.twitter_oauth_secret = access_token.secret + user.login = twitter_handle + user.token = access_token.token + user.secret = access_token.secret user.save end From f780f09b1ad6e4d1337073f2c0910172dad1f07f Mon Sep 17 00:00:00 2001 From: Jason Toy Date: Thu, 16 Sep 2010 09:48:06 -0700 Subject: [PATCH 2/4] configurable fields --- lib/devise/twitter.rb | 10 ++++++++++ lib/devise/twitter/version.rb | 2 +- lib/devise/twitter/warden.rb | 16 ++++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/devise/twitter.rb b/lib/devise/twitter.rb index 199d1c4..3746dce 100644 --- a/lib/devise/twitter.rb +++ b/lib/devise/twitter.rb @@ -12,6 +12,16 @@ module Twitter mattr_accessor :scope @@scope = nil + + mattr_accessor :twitter_handle_field + @@twitter_handle_field = "twitter_handle" + + mattr_accessor :twitter_oauth_token_field + @@twitter_oauth_token_field = "twitter_oauth_token" + + mattr_accessor :twitter_oauth_secret_field + @@twitter_oauth_secret_field = "twitter_oauth_secret" + # Default way to setup Devise. Run rails generate devise_install to create # a fresh initializer with all configuration values. def self.setup diff --git a/lib/devise/twitter/version.rb b/lib/devise/twitter/version.rb index f9e81ba..4bbe623 100644 --- a/lib/devise/twitter/version.rb +++ b/lib/devise/twitter/version.rb @@ -1,5 +1,5 @@ module Devise module Twitter - VERSION = "0.1.2.pre" + VERSION = "0.1.2" end end diff --git a/lib/devise/twitter/warden.rb b/lib/devise/twitter/warden.rb index 726b4b9..ebc449f 100644 --- a/lib/devise/twitter/warden.rb +++ b/lib/devise/twitter/warden.rb @@ -5,13 +5,13 @@ if perform_connect # Add twitter_handle to current user - already_existing_user = klass.first(:twitter_handle => twitter_handle) + already_existing_user = klass.first(Devise::Twitter.twitter_handle_field => twitter_handle) if already_existing_user.blank? # We don't know anyone with this handle, therefore continue with connecting user = @env['warden'].user - user.login = twitter_handle - user.token = access_token.token - user.secret = access_token.secret + user.send("#{Devise::Twitter.twitter_handle_field}=",twitter_handle) + user.send("#{Devise::Twitter.twitter_oauth_token_field}=", access_token.token) + user.send("#{Devise::Twitter.twitter_oauth_secret_field}=", access_token.secret) user.save return user else @@ -23,7 +23,7 @@ previous_user = @env['warden'].user # Try to find user by token - user = klass.first(:token=> access_token.token, :secret => access_token.secret) + user = klass.first(:Devise::Twitter.twitter_oauth_token_field=> access_token.token, Devise::Twitter.twitter_oauth_secret_field => access_token.secret) # Since we are logging in a new user we want to make sure the before_logout hook is called @env['warden'].logout if previous_user.present? @@ -31,9 +31,9 @@ if user.nil? # Create user if we don't know him yet user = klass.new - user.login = twitter_handle - user.token = access_token.token - user.secret = access_token.secret + user.send("#{Devise::Twitter.twitter_handle}=",twitter_handle) + user.send("#{Devise::Twitter.twitter_oauth_token}=", access_token.token) + user.send("#{Devise::Twitter.twitter_oauth_secret}=", access_token.secret) user.save end From 9d50865832c832dc31051b90b1d28337dcb0d055 Mon Sep 17 00:00:00 2001 From: Jason Toy Date: Thu, 16 Sep 2010 10:41:18 -0700 Subject: [PATCH 3/4] revert --- lib/devise/twitter/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/devise/twitter/version.rb b/lib/devise/twitter/version.rb index 4bbe623..f9e81ba 100644 --- a/lib/devise/twitter/version.rb +++ b/lib/devise/twitter/version.rb @@ -1,5 +1,5 @@ module Devise module Twitter - VERSION = "0.1.2" + VERSION = "0.1.2.pre" end end From 81c2f866e47ef197902c91b3ffd41c647e5f78fa Mon Sep 17 00:00:00 2001 From: Jason Toy Date: Sat, 18 Sep 2010 15:04:58 -0700 Subject: [PATCH 4/4] namecollision --- lib/devise/twitter.rb | 6 +++--- lib/devise/twitter/rack.rb | 4 ++-- lib/devise/twitter/version.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/devise/twitter.rb b/lib/devise/twitter.rb index 3746dce..596037c 100644 --- a/lib/devise/twitter.rb +++ b/lib/devise/twitter.rb @@ -28,9 +28,9 @@ def self.setup raise "Can not invoke setup twice" if @@setup_done yield self @@setup_done = true - + devise :twitterable_oauth Devise.warden do |manager| - manager.oauth(:twitter) do |twitter| + manager.oauth(:twitterable) do |twitter| twitter.consumer_key = @@consumer_key twitter.consumer_secret = @@consumer_secret twitter.options = { @@ -41,7 +41,7 @@ def self.setup :realm => "http://api.twitter.com/" } end - manager.default_strategies(:scope => @@scope).unshift :twitter_oauth + manager.default_strategies(:scope => @@scope).unshift :twitterable_oauth end end end diff --git a/lib/devise/twitter/rack.rb b/lib/devise/twitter/rack.rb index 6fb755c..328c10f 100644 --- a/lib/devise/twitter/rack.rb +++ b/lib/devise/twitter/rack.rb @@ -12,7 +12,7 @@ module Rack # Perform _only_ the twitter_oauth strategy. # Emulate _perform_authentication in _warden/proxy.rb - strategy = warden.send(:_fetch_strategy, :twitter_oauth, scope) + strategy = warden.send(:_fetch_strategy, :twitterable_oauth, scope) strategy.authenticate! if strategy.user warden.set_user(strategy.user, :event => :authentication, :scope => scope) @@ -21,7 +21,7 @@ module Rack redirect_to Warden::OAuth::Utils.host_with_port(request) else # Perform the redirect to Twitter - strategy = warden.send(:_fetch_strategy, :twitter_oauth, scope) + strategy = warden.send(:_fetch_strategy, :twitterable_oauth, scope) # warden_oauth would always redirect to / so we need to hook into it request_token = strategy.consumer.get_request_token(:oauth_callback => request.url) diff --git a/lib/devise/twitter/version.rb b/lib/devise/twitter/version.rb index f9e81ba..4bbe623 100644 --- a/lib/devise/twitter/version.rb +++ b/lib/devise/twitter/version.rb @@ -1,5 +1,5 @@ module Devise module Twitter - VERSION = "0.1.2.pre" + VERSION = "0.1.2" end end