authlogic-oid 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/README.rdoc +4 -4
- data/init.rb +1 -1
- data/lib/authlogic_openid/acts_as_authentic.rb +16 -17
- data/lib/authlogic_openid/session.rb +3 -2
- data/lib/authlogic_openid/version.rb +1 -1
- data/test/acts_as_authentic_test.rb +18 -3
- data/test/test_helper.rb +3 -3
- metadata +7 -5
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 1.0.4 released 2009-5-14
|
2
|
+
|
3
|
+
* Only authenticate with OpenID for models when a block is passed.
|
4
|
+
* Check for the existence of an openid_identifier field before including the model. Allowing this library to only be activated when present.
|
5
|
+
* Change required_field and optional_fields to openid_required_field and openid_optional_fields
|
6
|
+
|
1
7
|
== 1.0.3 released 2009-4-3
|
2
8
|
|
3
9
|
* Added find_by_openid_identifier config option for AuthlogicOpenid::Session.
|
data/README.rdoc
CHANGED
@@ -74,7 +74,7 @@ That's it! The rest is taken care of for you.
|
|
74
74
|
|
75
75
|
== Redirecting from the models?
|
76
76
|
|
77
|
-
If you are interested, I explain myself below. Regardless, you don't
|
77
|
+
If you are interested, I explain myself below. Regardless, if you don't feel comfortable with the organization of the logic,you can easily do this using the traditional method. As you saw in the setup instructions, this library leverages the open_id_authentication rails plugin. After the user has been authenticated just do this:
|
78
78
|
|
79
79
|
UserSession.create(@user)
|
80
80
|
|
@@ -82,11 +82,11 @@ It's that simple. For more information there is a great OpenID tutorial at: http
|
|
82
82
|
|
83
83
|
Now, here are my thoughts on the subject:
|
84
84
|
|
85
|
-
You are probably thinking: "Ben, you can't handle controller responsibilities in models". I agree with you on that comment, but my personal opinion is that these are not controller responsibilities. The fact that OpenID authentication requires a redirect should not effect the location of the logic / code. It's all part of the authentication process, which is the entire purpose of this library.
|
85
|
+
You are probably thinking: "Ben, you can't handle controller responsibilities in models". I agree with you on that comment, but my personal opinion is that these are not controller responsibilities. The fact that OpenID authentication requires a redirect should not effect the location of the logic / code. It's all part of the authentication process, which is the entire purpose of this library. This library is not one big module of code, its a collection of modules that all deal with OpenID authentication. These modules get included wherever it makes sense. That's the whole idea behind modules. To group common logic.
|
86
86
|
|
87
|
-
What if you wanted to authenticate with OpenID in multiple controllers in your application? You would probably pull out the common code into a module and include it in the respective controllers. Even better, you might create a class that elegantly handles this process and then place it in your lib directory.
|
87
|
+
Let's take a step back and look at the traditional method of OpenID authentication in rails. What if you wanted to authenticate with OpenID in multiple controllers in your application (Ex: registration and loggin in)? You would probably pull out the common code into a module and include it in the respective controllers. Even better, you might create a class that elegantly handles this process and then place it in your lib directory. Then, if you really wanted to be slick, you might take it another step further and have your models trigger this class during certain actions. Then what do we have? This exact library, that's exactly what this is.
|
88
88
|
|
89
|
-
The last thing I will leave you with, to get you thinking, is... where do sweepers lie in the MVC pattern?
|
89
|
+
The last thing I will leave you with, to get you thinking, is... where do sweepers lie in the MVC pattern? Without this, things like caching would be extremely difficult. There is a big difference between misplacing code / logic, and organizing logic into a separate module and hooking it in using the API provided by your models. Especially when the logic needs to be triggered by actions invoked on models.
|
90
90
|
|
91
91
|
Regardless, if I still haven't convinced you, I hope this library is of some benefit to you. At the very least an example of how to extend Authlogic.
|
92
92
|
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "
|
1
|
+
require File.dirname(__FILE__) + "/rails/init.rb"
|
@@ -22,24 +22,26 @@ module AuthlogicOpenid
|
|
22
22
|
#
|
23
23
|
# * <tt>Default:</tt> []
|
24
24
|
# * <tt>Accepts:</tt> Array of symbols
|
25
|
-
def
|
26
|
-
|
25
|
+
def openid_required_fields(value = nil)
|
26
|
+
rw_config(:openid_required_fields, value, [])
|
27
27
|
end
|
28
|
-
alias_method :
|
28
|
+
alias_method :openid_required_fields=, :openid_required_fields
|
29
29
|
|
30
30
|
# Same as required_fields, but optional instead.
|
31
31
|
#
|
32
32
|
# * <tt>Default:</tt> []
|
33
33
|
# * <tt>Accepts:</tt> Array of symbols
|
34
|
-
def
|
35
|
-
|
34
|
+
def openid_optional_fields(value = nil)
|
35
|
+
rw_config(:openid_optional_fields, value, [])
|
36
36
|
end
|
37
|
-
alias_method :
|
37
|
+
alias_method :openid_optional_fields=, :openid_optional_fields
|
38
38
|
end
|
39
39
|
|
40
40
|
module Methods
|
41
41
|
# Set up some simple validations
|
42
42
|
def self.included(klass)
|
43
|
+
return if !klass.column_names.include?("openid_identifier")
|
44
|
+
|
43
45
|
klass.class_eval do
|
44
46
|
validates_uniqueness_of :openid_identifier, :scope => validations_scope, :if => :using_openid?
|
45
47
|
validate :validate_openid
|
@@ -68,13 +70,10 @@ module AuthlogicOpenid
|
|
68
70
|
# Another advantage of taking this approach is that we can set fields from their OpenID profile before we save the record,
|
69
71
|
# if their OpenID provider supports it.
|
70
72
|
def save(perform_validation = true, &block)
|
71
|
-
if
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
else
|
76
|
-
false
|
77
|
-
end
|
73
|
+
return false if perform_validation && block_given? && authenticate_with_openid? && !authenticate_with_openid
|
74
|
+
result = super
|
75
|
+
yield(result) if block_given?
|
76
|
+
result
|
78
77
|
end
|
79
78
|
|
80
79
|
private
|
@@ -89,8 +88,8 @@ module AuthlogicOpenid
|
|
89
88
|
end
|
90
89
|
|
91
90
|
options = {}
|
92
|
-
options[:required] = self.class.
|
93
|
-
options[:optional] = self.class.
|
91
|
+
options[:required] = self.class.openid_required_fields
|
92
|
+
options[:optional] = self.class.openid_optional_fields
|
94
93
|
options[:return_to] = session_class.controller.url_for(:for_model => "1")
|
95
94
|
|
96
95
|
session_class.controller.send(:authenticate_with_open_id, openid_identifier, options) do |result, openid_identifier, registration|
|
@@ -127,7 +126,7 @@ module AuthlogicOpenid
|
|
127
126
|
# more just override this method and do whatever you want.
|
128
127
|
def attributes_to_save # :doc:
|
129
128
|
attrs_to_save = attributes.clone.delete_if do |k, v|
|
130
|
-
[:password, crypted_password_field, password_salt_field, :persistence_token, :perishable_token, :single_access_token, :login_count,
|
129
|
+
[:id, :password, crypted_password_field, password_salt_field, :persistence_token, :perishable_token, :single_access_token, :login_count,
|
131
130
|
:failed_login_count, :last_request_at, :current_login_at, :last_login_at, :current_login_ip, :last_login_ip, :created_at,
|
132
131
|
:updated_at, :lock_version].include?(k.to_sym)
|
133
132
|
end
|
@@ -151,7 +150,7 @@ module AuthlogicOpenid
|
|
151
150
|
end
|
152
151
|
|
153
152
|
def using_openid?
|
154
|
-
!openid_identifier.blank?
|
153
|
+
respond_to?(:openid_identifier) && !openid_identifier.blank?
|
155
154
|
end
|
156
155
|
|
157
156
|
def openid_complete?
|
@@ -25,7 +25,7 @@ module AuthlogicOpenid
|
|
25
25
|
# * <tt>Default:</tt> :find_by_openid_identifier
|
26
26
|
# * <tt>Accepts:</tt> Symbol
|
27
27
|
def find_by_openid_identifier_method(value = nil)
|
28
|
-
|
28
|
+
rw_config(:find_by_openid_identifier_method, value, :find_by_openid_identifier)
|
29
29
|
end
|
30
30
|
alias_method :find_by_openid_identifier_method=, :find_by_openid_identifier_method
|
31
31
|
end
|
@@ -72,7 +72,8 @@ module AuthlogicOpenid
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def validate_by_openid
|
75
|
-
controller.
|
75
|
+
self.remember_me = controller.params[:remember_me] == "true" if controller.params.key?(:remember_me)
|
76
|
+
controller.send(:authenticate_with_open_id, openid_identifier, :return_to => controller.url_for(:for_session => "1", :remember_me => remember_me?)) do |result, openid_identifier|
|
76
77
|
if result.unsuccessful?
|
77
78
|
errors.add_to_base(result.message)
|
78
79
|
return
|
@@ -13,7 +13,7 @@ class ActsAsAuthenticTest < ActiveSupport::TestCase
|
|
13
13
|
user.login = "sweet"
|
14
14
|
user.email = "a@a.com"
|
15
15
|
user.openid_identifier = "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"
|
16
|
-
assert !user.save # because we are redirecting, the user was NOT saved
|
16
|
+
assert !user.save {} # because we are redirecting, the user was NOT saved
|
17
17
|
assert redirecting_to_yahoo?
|
18
18
|
end
|
19
19
|
|
@@ -32,7 +32,7 @@ class ActsAsAuthenticTest < ActiveSupport::TestCase
|
|
32
32
|
assert ben.save
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def test_password_required_on_update
|
36
36
|
ben = users(:ben)
|
37
37
|
ben.openid_identifier = nil
|
38
38
|
assert_nil ben.crypted_password
|
@@ -68,7 +68,7 @@ class ActsAsAuthenticTest < ActiveSupport::TestCase
|
|
68
68
|
def test_updating_with_openid
|
69
69
|
ben = users(:ben)
|
70
70
|
ben.openid_identifier = "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"
|
71
|
-
assert !ben.save # because we are redirecting
|
71
|
+
assert !ben.save {} # because we are redirecting
|
72
72
|
assert redirecting_to_yahoo?
|
73
73
|
end
|
74
74
|
|
@@ -87,4 +87,19 @@ class ActsAsAuthenticTest < ActiveSupport::TestCase
|
|
87
87
|
assert ben.save(false)
|
88
88
|
assert !redirecting_to_yahoo?
|
89
89
|
end
|
90
|
+
|
91
|
+
def test_updating_without_a_block
|
92
|
+
ben = users(:ben)
|
93
|
+
ben.openid_identifier = "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"
|
94
|
+
assert ben.save
|
95
|
+
ben.reload
|
96
|
+
assert_equal "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--", ben.openid_identifier
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_updating_while_not_activated
|
100
|
+
UserSession.controller = nil
|
101
|
+
ben = users(:ben)
|
102
|
+
ben.openid_identifier = "https://me.yahoo.com/a/9W0FJjRj0o981TMSs0vqVxPdmMUVOQ--"
|
103
|
+
assert ben.save {}
|
104
|
+
end
|
90
105
|
end
|
data/test/test_helper.rb
CHANGED
@@ -45,11 +45,11 @@ end
|
|
45
45
|
|
46
46
|
require "active_record/fixtures"
|
47
47
|
require "openid"
|
48
|
+
Rails = true # to trick authlogic into loading the rails adapter
|
48
49
|
require File.dirname(__FILE__) + "/../../authlogic/lib/authlogic"
|
49
50
|
require File.dirname(__FILE__) + "/../../authlogic/lib/authlogic/test_case"
|
50
|
-
require File.dirname(__FILE__) + "/libs/rails_trickery"
|
51
|
+
#require File.dirname(__FILE__) + "/libs/rails_trickery"
|
51
52
|
require File.dirname(__FILE__) + '/libs/open_id_authentication/lib/open_id_authentication'
|
52
|
-
ActionController.send(:include, OpenIdAuthentication)
|
53
53
|
require File.dirname(__FILE__) + '/../lib/authlogic_openid' unless defined?(AuthlogicOpenid)
|
54
54
|
require File.dirname(__FILE__) + '/libs/user'
|
55
55
|
require File.dirname(__FILE__) + '/libs/user_session'
|
@@ -69,7 +69,7 @@ class ActiveSupport::TestCase
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def controller
|
72
|
-
@controller ||= Authlogic::
|
72
|
+
@controller ||= Authlogic::ControllerAdapters::RailsAdapter.new(ActionController.new)
|
73
73
|
end
|
74
74
|
|
75
75
|
def redirecting_to_yahoo?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authlogic-oid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Johnson of Binary Logic
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-31 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.12.
|
33
|
+
version: 1.12.2
|
34
34
|
version:
|
35
35
|
description: Extension of the Authlogic library to add OpenID support.
|
36
36
|
email: bjohnson@binarylogic.com
|
@@ -83,6 +83,8 @@ files:
|
|
83
83
|
- test/test_helper.rb
|
84
84
|
has_rdoc: true
|
85
85
|
homepage: http://github.com/binarylogic/authlogic_openid
|
86
|
+
licenses: []
|
87
|
+
|
86
88
|
post_install_message:
|
87
89
|
rdoc_options:
|
88
90
|
- --main
|
@@ -104,9 +106,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
106
|
requirements: []
|
105
107
|
|
106
108
|
rubyforge_project: authlogic-oid
|
107
|
-
rubygems_version: 1.3.
|
109
|
+
rubygems_version: 1.3.4
|
108
110
|
signing_key:
|
109
|
-
specification_version:
|
111
|
+
specification_version: 3
|
110
112
|
summary: Extension of the Authlogic library to add OpenID support.
|
111
113
|
test_files:
|
112
114
|
- test/acts_as_authentic_test.rb
|