authlogic-oauth 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/.git/COMMIT_EDITMSG +71 -0
  2. data/.git/FETCH_HEAD +1 -0
  3. data/.git/HEAD +1 -0
  4. data/.git/config +12 -0
  5. data/.git/description +1 -0
  6. data/.git/hooks/applypatch-msg.sample +15 -0
  7. data/.git/hooks/commit-msg.sample +24 -0
  8. data/.git/hooks/post-commit.sample +8 -0
  9. data/.git/hooks/post-receive.sample +15 -0
  10. data/.git/hooks/post-update.sample +8 -0
  11. data/.git/hooks/pre-applypatch.sample +14 -0
  12. data/.git/hooks/pre-commit.sample +18 -0
  13. data/.git/hooks/pre-rebase.sample +169 -0
  14. data/.git/hooks/prepare-commit-msg.sample +36 -0
  15. data/.git/hooks/update.sample +107 -0
  16. data/.git/index +0 -0
  17. data/.git/info/exclude +6 -0
  18. data/.git/logs/HEAD +8 -0
  19. data/.git/logs/refs/heads/master +6 -0
  20. data/.git/logs/refs/remotes/origin/HEAD +1 -0
  21. data/.git/logs/refs/remotes/origin/master +5 -0
  22. data/.git/objects/1a/7e60fbbc011b519f1f19dbca839cfd907924a3 +0 -0
  23. data/.git/objects/2e/f242d63b205e88b003d10e96d7d31269bd7073 +0 -0
  24. data/.git/objects/41/6b196f0d3fa02be32bdd0bd7d6a3fd7d57844d +0 -0
  25. data/.git/objects/42/607cc77682553f3d71ef40e5fae408ac3351f4 +0 -0
  26. data/.git/objects/56/6625e05678ab5d52511225fa360e6934e049f6 +0 -0
  27. data/.git/objects/56/947322f2e948b597b9e692320ecada30315e45 +0 -0
  28. data/.git/objects/87/a7f6af123ffd70a8cd751b80ec4d4a9de69ab9 +0 -0
  29. data/.git/objects/ab/14db4dd48cb6f4c3688eb65513afac383d3584 +0 -0
  30. data/.git/objects/b2/9bfce970d5a817d2f7626b2984dc8de67ab774 +0 -0
  31. data/.git/objects/e0/a81debca6c11c68732b3769d1f83c5c3c97c09 +0 -0
  32. data/.git/objects/e3/74f7848330d167432299a84e43c7af18a51b87 +2 -0
  33. data/.git/objects/f3/5e9e44d75a11221b0c2f2b2a0bdb5b37bfbaa1 +0 -0
  34. data/.git/objects/pack/pack-2b55f15bfde87d738b79905b5c0788e4a4cbf3af.idx +0 -0
  35. data/.git/objects/pack/pack-2b55f15bfde87d738b79905b5c0788e4a4cbf3af.pack +0 -0
  36. data/.git/packed-refs +2 -0
  37. data/.git/refs/heads/master +1 -0
  38. data/.git/refs/remotes/origin/HEAD +1 -0
  39. data/.git/refs/remotes/origin/master +1 -0
  40. data/CHANGELOG.rdoc +4 -0
  41. data/MIT-LICENSE +20 -0
  42. data/Manifest.txt +57 -0
  43. data/README.rdoc +120 -0
  44. data/Rakefile +20 -0
  45. data/init.rb +1 -0
  46. data/lib/authlogic_oauth/acts_as_authentic.rb +116 -0
  47. data/lib/authlogic_oauth/oauth_process.rb +61 -0
  48. data/lib/authlogic_oauth/session.rb +73 -0
  49. data/lib/authlogic_oauth/version.rb +51 -0
  50. data/lib/authlogic_oauth.rb +7 -0
  51. data/rails/init.rb +1 -0
  52. data/test/acts_as_authentic_test.rb +100 -0
  53. data/test/fixtures/users.yml +6 -0
  54. data/test/lib/user.rb +3 -0
  55. data/test/lib/user_session.rb +7 -0
  56. data/test/session_test.rb +27 -0
  57. data/test/test_helper.rb +49 -0
  58. data.tar.gz.sig +0 -0
  59. metadata +155 -0
  60. metadata.gz.sig +0 -0
data/.git/index ADDED
Binary file
data/.git/info/exclude ADDED
@@ -0,0 +1,6 @@
1
+ # git-ls-files --others --exclude-from=.git/info/exclude
2
+ # Lines that start with '#' are comments.
3
+ # For a project mostly in C, the following would be a good set of
4
+ # exclude patterns (uncomment them if you want to use them):
5
+ # *.[oa]
6
+ # *~
data/.git/logs/HEAD ADDED
@@ -0,0 +1,8 @@
1
+ 0000000000000000000000000000000000000000 6976eeb5a95a2b5f48cfea6041b0290b11f90597 jrallison <jrallison@gmail.com> 1243800566 -0400 clone: from git://github.com/jrallison/authlogic_oauth.git
2
+ 6976eeb5a95a2b5f48cfea6041b0290b11f90597 6976eeb5a95a2b5f48cfea6041b0290b11f90597 jrallison <jrallison@gmail.com> 1243800566 -0400 checkout: moving from master to 6976eeb5a95a2b5f48cfea6041b0290b11f90597
3
+ 6976eeb5a95a2b5f48cfea6041b0290b11f90597 6976eeb5a95a2b5f48cfea6041b0290b11f90597 jrallison <jrallison@gmail.com> 1243800602 -0400 checkout: moving from 6976eeb5a95a2b5f48cfea6041b0290b11f90597 to master
4
+ 6976eeb5a95a2b5f48cfea6041b0290b11f90597 ab14db4dd48cb6f4c3688eb65513afac383d3584 jrallison <jrallison@gmail.com> 1243800623 -0400 commit: Adding link to oauth example app
5
+ ab14db4dd48cb6f4c3688eb65513afac383d3584 1a7e60fbbc011b519f1f19dbca839cfd907924a3 jrallison <jrallison@gmail.com> 1243801464 -0400 commit: Updating README
6
+ 1a7e60fbbc011b519f1f19dbca839cfd907924a3 e374f7848330d167432299a84e43c7af18a51b87 jrallison <jrallison@gmail.com> 1243801583 -0400 commit: Changing next steps area for better readablility
7
+ e374f7848330d167432299a84e43c7af18a51b87 42607cc77682553f3d71ef40e5fae408ac3351f4 jrallison <jrallison@gmail.com> 1243803219 -0400 commit: Updating summary and description
8
+ 42607cc77682553f3d71ef40e5fae408ac3351f4 41029da703a9502cada88f88b58facd4dc023d53 jrallison <jrallison@gmail.com> 1243803541 -0400 commit: Updating Manifest
@@ -0,0 +1,6 @@
1
+ 0000000000000000000000000000000000000000 6976eeb5a95a2b5f48cfea6041b0290b11f90597 jrallison <jrallison@gmail.com> 1243800566 -0400 clone: from git://github.com/jrallison/authlogic_oauth.git
2
+ 6976eeb5a95a2b5f48cfea6041b0290b11f90597 ab14db4dd48cb6f4c3688eb65513afac383d3584 jrallison <jrallison@gmail.com> 1243800623 -0400 commit: Adding link to oauth example app
3
+ ab14db4dd48cb6f4c3688eb65513afac383d3584 1a7e60fbbc011b519f1f19dbca839cfd907924a3 jrallison <jrallison@gmail.com> 1243801464 -0400 commit: Updating README
4
+ 1a7e60fbbc011b519f1f19dbca839cfd907924a3 e374f7848330d167432299a84e43c7af18a51b87 jrallison <jrallison@gmail.com> 1243801583 -0400 commit: Changing next steps area for better readablility
5
+ e374f7848330d167432299a84e43c7af18a51b87 42607cc77682553f3d71ef40e5fae408ac3351f4 jrallison <jrallison@gmail.com> 1243803219 -0400 commit: Updating summary and description
6
+ 42607cc77682553f3d71ef40e5fae408ac3351f4 41029da703a9502cada88f88b58facd4dc023d53 jrallison <jrallison@gmail.com> 1243803541 -0400 commit: Updating Manifest
@@ -0,0 +1 @@
1
+ 0000000000000000000000000000000000000000 6976eeb5a95a2b5f48cfea6041b0290b11f90597 jrallison <jrallison@gmail.com> 1243800566 -0400 clone: from git://github.com/jrallison/authlogic_oauth.git
@@ -0,0 +1,5 @@
1
+ 6976eeb5a95a2b5f48cfea6041b0290b11f90597 ab14db4dd48cb6f4c3688eb65513afac383d3584 John Allison <jallison@jrallison.local> 1243800663 -0400 update by push
2
+ ab14db4dd48cb6f4c3688eb65513afac383d3584 1a7e60fbbc011b519f1f19dbca839cfd907924a3 John Allison <jallison@jrallison.local> 1243801484 -0400 update by push
3
+ 1a7e60fbbc011b519f1f19dbca839cfd907924a3 e374f7848330d167432299a84e43c7af18a51b87 John Allison <jallison@jrallison.local> 1243801613 -0400 update by push
4
+ e374f7848330d167432299a84e43c7af18a51b87 42607cc77682553f3d71ef40e5fae408ac3351f4 John Allison <jallison@jrallison.local> 1243803245 -0400 update by push
5
+ 42607cc77682553f3d71ef40e5fae408ac3351f4 41029da703a9502cada88f88b58facd4dc023d53 John Allison <jallison@jrallison.local> 1243803554 -0400 update by push
@@ -0,0 +1,2 @@
1
+ x��Qj�0D�S���lIJ�'ٕV��,[������7�`��m+�.�6�s��t�ɣK&��,{��O�8b�z�!���Eg�yƐ1cH�O!�� �Ҥ����Zν��?~��z���h��5�~�7m�V��./L���Z�
2
+ M�;�]�' m�<LX�^GMĵ���/�U�
data/.git/packed-refs ADDED
@@ -0,0 +1,2 @@
1
+ # pack-refs with: peeled
2
+ 6976eeb5a95a2b5f48cfea6041b0290b11f90597 refs/remotes/origin/master
@@ -0,0 +1 @@
1
+ 41029da703a9502cada88f88b58facd4dc023d53
@@ -0,0 +1 @@
1
+ ref: refs/remotes/origin/master
@@ -0,0 +1 @@
1
+ 41029da703a9502cada88f88b58facd4dc023d53
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,4 @@
1
+ = Authlogic OAuth
2
+
3
+ Authlogic OAuth
4
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 John Allison (johnallison.me)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,57 @@
1
+ .git/COMMIT_EDITMSG
2
+ .git/FETCH_HEAD
3
+ .git/HEAD
4
+ .git/config
5
+ .git/description
6
+ .git/hooks/applypatch-msg.sample
7
+ .git/hooks/commit-msg.sample
8
+ .git/hooks/post-commit.sample
9
+ .git/hooks/post-receive.sample
10
+ .git/hooks/post-update.sample
11
+ .git/hooks/pre-applypatch.sample
12
+ .git/hooks/pre-commit.sample
13
+ .git/hooks/pre-rebase.sample
14
+ .git/hooks/prepare-commit-msg.sample
15
+ .git/hooks/update.sample
16
+ .git/index
17
+ .git/info/exclude
18
+ .git/logs/HEAD
19
+ .git/logs/refs/heads/master
20
+ .git/logs/refs/remotes/origin/HEAD
21
+ .git/logs/refs/remotes/origin/master
22
+ .git/objects/1a/7e60fbbc011b519f1f19dbca839cfd907924a3
23
+ .git/objects/2e/f242d63b205e88b003d10e96d7d31269bd7073
24
+ .git/objects/41/6b196f0d3fa02be32bdd0bd7d6a3fd7d57844d
25
+ .git/objects/42/607cc77682553f3d71ef40e5fae408ac3351f4
26
+ .git/objects/56/6625e05678ab5d52511225fa360e6934e049f6
27
+ .git/objects/56/947322f2e948b597b9e692320ecada30315e45
28
+ .git/objects/87/a7f6af123ffd70a8cd751b80ec4d4a9de69ab9
29
+ .git/objects/ab/14db4dd48cb6f4c3688eb65513afac383d3584
30
+ .git/objects/b2/9bfce970d5a817d2f7626b2984dc8de67ab774
31
+ .git/objects/e0/a81debca6c11c68732b3769d1f83c5c3c97c09
32
+ .git/objects/e3/74f7848330d167432299a84e43c7af18a51b87
33
+ .git/objects/f3/5e9e44d75a11221b0c2f2b2a0bdb5b37bfbaa1
34
+ .git/objects/pack/pack-2b55f15bfde87d738b79905b5c0788e4a4cbf3af.idx
35
+ .git/objects/pack/pack-2b55f15bfde87d738b79905b5c0788e4a4cbf3af.pack
36
+ .git/packed-refs
37
+ .git/refs/heads/master
38
+ .git/refs/remotes/origin/HEAD
39
+ .git/refs/remotes/origin/master
40
+ CHANGELOG.rdoc
41
+ MIT-LICENSE
42
+ Manifest.txt
43
+ README.rdoc
44
+ Rakefile
45
+ init.rb
46
+ lib/authlogic_oauth.rb
47
+ lib/authlogic_oauth/acts_as_authentic.rb
48
+ lib/authlogic_oauth/oauth_process.rb
49
+ lib/authlogic_oauth/session.rb
50
+ lib/authlogic_oauth/version.rb
51
+ rails/init.rb
52
+ test/acts_as_authentic_test.rb
53
+ test/fixtures/users.yml
54
+ test/lib/user.rb
55
+ test/lib/user_session.rb
56
+ test/session_test.rb
57
+ test/test_helper.rb
data/README.rdoc ADDED
@@ -0,0 +1,120 @@
1
+ = Authlogic OAuth
2
+
3
+ Authlogic OAuth is an extension of the Authlogic library to add OAuth support. One use case for authentication with OAuth is allowing users to log in with their Twitter credentials.
4
+
5
+ == Helpful links
6
+
7
+ * <b>Authlogic:</b> http://github.com/binarylogic/authlogic
8
+ * <b>OAuth Example Project:</b> http://github.com/jrallison/authlogic_example/tree/with-oauth
9
+ * <b>Live example:</b> *coming soon*
10
+
11
+ == Install and use
12
+
13
+ === 1. Install Authlogic and setup your application
14
+
15
+ <b>Authlogic:</b> http://github.com/binarylogic/authlogic
16
+ <b>Authlogic Example:</b> http://github.com/binarylogic/authlogic_example
17
+
18
+ === 2. Install OAuth and Authlogic_Oauth
19
+
20
+ $ sudo gem install oauth
21
+ $ sudo gem install authlogic-oauth
22
+
23
+ Now add the gem dependencies in your config:
24
+
25
+ config.gem "oauth"
26
+ config.gem "authlogic-oauth", :lib => "authlogic_oauth"
27
+
28
+ Or for older version of rails, install it as a plugin:
29
+
30
+ $ script/plugin install git://github.com/jrallison/authlogic_oauth.git
31
+
32
+ === 3. Make some simple changes to your database:
33
+
34
+ class AddUsersOauthFields < ActiveRecord::Migration
35
+ def self.up
36
+ add_column :users, :oauth_token, :string
37
+ add_column :users, :oauth_secret, :string
38
+ add_index :users, :oauth_token
39
+
40
+ change_column :users, :login, :string, :default => nil, :null => true
41
+ change_column :users, :crypted_password, :string, :default => nil, :null => true
42
+ change_column :users, :password_salt, :string, :default => nil, :null => true
43
+ end
44
+
45
+ def self.down
46
+ remove_column :users, :oauth_token
47
+ remove_column :users, :oauth_secret
48
+
49
+ [:login, :crypted_password, :password_salt].each do |field|
50
+ User.all(:conditions => "#{field} is NULL").each { |user| user.update_attribute(field, "") if user.send(field).nil? }
51
+ change_column :users, field, :string, :default => "", :null => false
52
+ end
53
+ end
54
+ end
55
+
56
+ === 4. Make sure you save your objects properly
57
+
58
+ You only need to save your objects this way if you want the user to authenticate with their OAuth provider.
59
+
60
+ That being said, you probably want to do this in your controllers. You should do this for BOTH your User objects and UserSession objects (assuming you are authenticating users). It should look something like this:
61
+
62
+ @user_session.save do |result|
63
+ if result
64
+ flash[:notice] = "Login successful!"
65
+ redirect_back_or_default account_url
66
+ else
67
+ render :action => :new
68
+ end
69
+ end
70
+
71
+ You should save your @user objects this way as well, because you also want the user to authenticate with OAuth.
72
+
73
+ Notice we are saving with a block. Why? Because we need to redirect the user to their OAuth provider so that they can authenticate. When we do this, we don't want to execute that block of code, because if we do, we will get a DoubleRender error. This lets us skip that entire block and send the user along their way without any problems.
74
+
75
+ === 5. Add a few routes and a OAuth controller
76
+
77
+ This area needs improvement. Also, because of security issues with OAuth callbacks, this is a bit more complicated then it needs to be.
78
+
79
+ Add the following routes to your routes.rb file:
80
+
81
+ map.oauth_login '/oauth_login', { :controller => 'user_sessions', :action => 'create', :method => 'get' }
82
+ map.oauth_register '/oauth_register', { :controller => 'users', :action => 'create', :method => 'get' }
83
+ map.authorize_oauth '/oauth', { :controller => 'oauth', :action => 'authorize', :method => 'get' }
84
+
85
+ Add an OAuth controller to handle the callback from your OAuth provider, and send it on it's way.
86
+
87
+ class OauthController < ApplicationController
88
+ def authorize
89
+ redirect_to session[:oauth_redirect].merge(:oauth_token => params[:oauth_token])
90
+ end
91
+ end
92
+
93
+ === 6. Config your OAuth provider's callback url
94
+
95
+ You're callback url should point to the authorize route you added in step 5.
96
+
97
+ === 7. Define the oauth_consumer class method on your UserSession model
98
+
99
+ The oauth_consumer should return an OAuth::Consumer which is configured for your OAuth provider. Here's an example for Twitter:
100
+
101
+ class UserSession < Authlogic::Session::Base
102
+
103
+ def self.oauth_consumer
104
+ OAuth::Consumer.new("TOKEN", "SECRET",
105
+ { :site=>"http://twitter.com",
106
+ :authorize_url => "http://twitter.com/oauth/authenticate" })
107
+ end
108
+
109
+ end
110
+
111
+ That's it! The rest is taken care of for you.
112
+
113
+ = Here are some next steps for the plugin.
114
+
115
+ 1. Safe OAuth error handling.
116
+ 2. Helpers for login/register with oauth form buttons.
117
+ 3. Add callback for populating user fields with data retrieved from OAuth before account is saved during registration.
118
+ 4. Remove oauth request from the Rails request cycle.
119
+ 5. Cleaning up OAuth controller and routes when OAuth callback_url parameter is fixed ... or discovered an alternative way of handling it.
120
+
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ ENV['RDOCOPT'] = "-S -f html -T hanna"
2
+
3
+ require "rubygems"
4
+ require "hoe"
5
+ require File.dirname(__FILE__) << "/lib/authlogic_oauth/version"
6
+
7
+ Hoe.new("authlogic-oauth", AuthlogicOauth::Version::STRING) do |p|
8
+ p.name = "authlogic-oauth"
9
+ p.author = "John Allison"
10
+ p.email = 'jrallison@gmail.com'
11
+ p.summary = "An authlogic extension for authenticating via OAuth. (I.E. Twitter login)"
12
+ p.description = "An authlogic extension for authenticating via OAuth. This can be helpful for adding support for login/registration with Twitter credentials."
13
+ p.url = "http://github.com/jrallison/authlogic_oauth"
14
+ p.history_file = "CHANGELOG.rdoc"
15
+ p.readme_file = "README.rdoc"
16
+ p.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc"]
17
+ p.remote_rdoc_dir = ''
18
+ p.test_globs = ["test/*/test_*.rb", "test/*_test.rb", "test/*/*_test.rb"]
19
+ p.extra_deps = %w(activesupport)
20
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ File.dirname(__FILE__) + "/rails/init.rb"
@@ -0,0 +1,116 @@
1
+ module AuthlogicOauth
2
+ module ActsAsAuthentic
3
+ def self.included(klass)
4
+ klass.class_eval do
5
+ extend Config
6
+ add_acts_as_authentic_module(Methods, :prepend)
7
+ end
8
+ end
9
+
10
+ module Config
11
+ # The name of the oauth token field in the database.
12
+ #
13
+ # * <tt>Default:</tt> :oauth_token
14
+ # * <tt>Accepts:</tt> Symbol
15
+ def oauth_token_field(value = nil)
16
+ rw_config(:oauth_token_field, value, :oauth_token)
17
+ end
18
+ alias_method :oauth_token_field=, :oauth_token_field
19
+
20
+ # The name of the oauth token secret field in the database.
21
+ #
22
+ # * <tt>Default:</tt> :oauth_secret
23
+ # * <tt>Accepts:</tt> Symbol
24
+ def oauth_secret_field(value = nil)
25
+ rw_config(:oauth_secret_field, value, :oauth_secret)
26
+ end
27
+ alias_method :oauth_secret_field=, :oauth_secret_field
28
+ end
29
+
30
+ module Methods
31
+ include OauthProcess
32
+
33
+ # Set up some simple validations
34
+ def self.included(klass)
35
+ klass.class_eval do
36
+ alias_method "#{oauth_token_field.to_s}=".to_sym, :oauth_token=
37
+ alias_method "#{oauth_secret_field.to_s}=".to_sym, :oauth_secret=
38
+ end
39
+
40
+ return if !klass.column_names.include?(klass.oauth_token_field.to_s)
41
+
42
+ klass.class_eval do
43
+ validate :validate_by_oauth, :if => :authenticating_with_oauth?
44
+
45
+ validates_uniqueness_of klass.oauth_token_field, :scope => validations_scope, :if => :using_oauth?
46
+ validates_presence_of klass.oauth_secret_field, :scope => validations_scope, :if => :using_oauth?
47
+
48
+ validates_length_of_password_field_options validates_length_of_password_field_options.merge(:if => :validate_password_with_oauth?)
49
+ validates_confirmation_of_password_field_options validates_confirmation_of_password_field_options.merge(:if => :validate_password_with_oauth?)
50
+ validates_length_of_password_confirmation_field_options validates_length_of_password_confirmation_field_options.merge(:if => :validate_password_with_oauth?)
51
+ validates_length_of_login_field_options validates_length_of_login_field_options.merge(:if => :validate_password_with_oauth?)
52
+ validates_format_of_login_field_options validates_format_of_login_field_options.merge(:if => :validate_password_with_oauth?)
53
+ end
54
+
55
+ # email needs to be optional for oauth
56
+ klass.validate_email_field = false
57
+ end
58
+
59
+ def save(perform_validation = true, &block)
60
+ if perform_validation && block_given? && redirecting_to_oauth_server?
61
+ redirect_to_oauth
62
+ return false
63
+ end
64
+
65
+ result = super
66
+ yield(result) if block_given?
67
+ result
68
+ end
69
+
70
+ # Set the oauth fields
71
+ def oauth_token=(value)
72
+ write_attribute(oauth_token_field, value.blank? ? nil : value)
73
+ end
74
+
75
+ def oauth_secret=(value)
76
+ write_attribute(oauth_secret_field, value.blank? ? nil : value)
77
+ end
78
+
79
+ private
80
+
81
+ def authenticating_with_oauth?
82
+ !session_class.controller.params[:register_with_oauth].blank? || oauth_response
83
+ end
84
+
85
+ def authenticate_with_oauth
86
+ access_token = generate_access_token
87
+
88
+ self.oauth_token = access_token.token
89
+ self.oauth_secret = access_token.secret
90
+ end
91
+
92
+ def access_token
93
+ OAuth::AccessToken.new(oauth,
94
+ read_attribute(oauth_token_field),
95
+ read_attribute(oauth_secret_field))
96
+ end
97
+
98
+ def using_oauth?
99
+ respond_to?(oauth_token_field) && !oauth_token.blank?
100
+ end
101
+
102
+ def validate_password_with_oauth?
103
+ !using_oauth? && require_password?
104
+ end
105
+
106
+ def oauth_token_field
107
+ self.class.oauth_token_field
108
+ end
109
+
110
+ def oauth_secret_field
111
+ self.class.oauth_secret_field
112
+ end
113
+
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,61 @@
1
+ module AuthlogicOauth
2
+ module OauthProcess
3
+
4
+ private
5
+
6
+ def validate_by_oauth
7
+ validate_email_field = false
8
+
9
+ if oauth_response.blank?
10
+ redirect_to_oauth
11
+ else
12
+ authenticate_with_oauth
13
+ end
14
+ end
15
+
16
+ def redirecting_to_oauth_server?
17
+ authenticating_with_oauth? && oauth_response.blank?
18
+ end
19
+
20
+ def redirect_to_oauth
21
+ request = oauth.get_request_token
22
+ oauth_controller.session[:oauth_request_token] = request.token
23
+ oauth_controller.session[:oauth_request_token_secret] = request.secret
24
+
25
+ # Send to oauth authorize url and redirect back to the current action
26
+ oauth_controller.session[:oauth_redirect] = build_callback_url
27
+ oauth_controller.redirect_to request.authorize_url
28
+ end
29
+
30
+ def build_callback_url
31
+ { :controller => oauth_controller.controller_name, :action => oauth_controller.action_name }
32
+ end
33
+
34
+ def request_token
35
+ OAuth::RequestToken.new(oauth,
36
+ oauth_controller.session[:oauth_request_token],
37
+ oauth_controller.session[:oauth_request_token_secret])
38
+ end
39
+
40
+ def generate_access_token
41
+ request_token.get_access_token
42
+ end
43
+
44
+ def oauth_response
45
+ oauth_controller.params[:oauth_token]
46
+ end
47
+
48
+ def oauth_controller
49
+ is_auth_session? ? controller : session_class.controller
50
+ end
51
+
52
+ def oauth
53
+ is_auth_session? ? self.class.oauth_consumer : session_class.oauth_consumer
54
+ end
55
+
56
+ def is_auth_session?
57
+ self.is_a?(Authlogic::Session::Base)
58
+ end
59
+
60
+ end
61
+ end