Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Change from using config to the new rw_config. Requires the latest ve…

…rsion of authlogic. config was too general of a name and was causing conflicts for people in their own projects.
  • Loading branch information...
commit 8a8c7729cf5590636892535167a86fffd40650b4 1 parent 77def85
Ben Johnson yourewelcome authored
4 CHANGELOG.rdoc
Source Rendered
... ... @@ -1,6 +1,8 @@
1   -== 1.0.4
  1 +== 1.0.4 released 2009-5-14
2 2
3 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
4 6
5 7 == 1.0.3 released 2009-4-3
6 8
8 README.rdoc
Source Rendered
@@ -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 have to use this library. As you saw in the setup instructions, this library leverages the open_id_authentication rails plugin. You can EASILY use this in your controllers and do your traditional OpenID authentication yourself. After the user has been authenticated just do this:
  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. The logic that handles this process should be in it's own domain, which is the definition of the "M" in MVC. The "M" doesn't have to just be a data access layer, it's a place for domain logic.
  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. That's exactly what this is.
  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
2  init.rb
... ... @@ -1 +1 @@
1   -require "authlogic_openid"
  1 +require File.dirname(__FILE__) + "/rails/init.rb"
22 lib/authlogic_openid/acts_as_authentic.rb
@@ -22,24 +22,26 @@ module Config
22 22 #
23 23 # * <tt>Default:</tt> []
24 24 # * <tt>Accepts:</tt> Array of symbols
25   - def required_fields(value = nil)
26   - config(:required_fields, value, [])
  25 + def openid_required_fields(value = nil)
  26 + rw_config(:openid_required_fields, value, [])
27 27 end
28   - alias_method :required_fields=, :required_fields
  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 optional_fields(value = nil)
35   - config(:optional_fields, value, [])
  34 + def openid_optional_fields(value = nil)
  35 + rw_config(:openid_optional_fields, value, [])
36 36 end
37   - alias_method :optional_fields=, :optional_fields
  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
@@ -86,8 +88,8 @@ def authenticate_with_openid
86 88 end
87 89
88 90 options = {}
89   - options[:required] = self.class.required_fields
90   - options[:optional] = self.class.optional_fields
  91 + options[:required] = self.class.openid_required_fields
  92 + options[:optional] = self.class.openid_optional_fields
91 93 options[:return_to] = session_class.controller.url_for(:for_model => "1")
92 94
93 95 session_class.controller.send(:authenticate_with_open_id, openid_identifier, options) do |result, openid_identifier, registration|
@@ -124,7 +126,7 @@ def map_openid_registration(registration) # :doc:
124 126 # more just override this method and do whatever you want.
125 127 def attributes_to_save # :doc:
126 128 attrs_to_save = attributes.clone.delete_if do |k, v|
127   - [: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,
128 130 :failed_login_count, :last_request_at, :current_login_at, :last_login_at, :current_login_ip, :last_login_ip, :created_at,
129 131 :updated_at, :lock_version].include?(k.to_sym)
130 132 end
@@ -148,7 +150,7 @@ def validate_openid
148 150 end
149 151
150 152 def using_openid?
151   - !openid_identifier.blank?
  153 + respond_to?(:openid_identifier) && !openid_identifier.blank?
152 154 end
153 155
154 156 def openid_complete?
7 lib/authlogic_openid/session.rb
@@ -25,7 +25,7 @@ module Config
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   - config(:find_by_openid_identifier_method, value, :find_by_openid_identifier)
  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,12 +72,15 @@ def find_by_openid_identifier_method
72 72 end
73 73
74 74 def validate_by_openid
75   - controller.send(:authenticate_with_open_id, openid_identifier, :return_to => controller.url_for(:for_session => "1")) do |result, openid_identifier|
  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
79 80 end
80 81
  82 + raise "#{openid_identifier.inspect} ::: #{controller.params["openid.claimed_id"]}"
  83 +
81 84 self.attempted_record = klass.send(find_by_openid_identifier_method, openid_identifier)
82 85
83 86 if !attempted_record
2  lib/authlogic_openid/version.rb
@@ -41,7 +41,7 @@ def to_a
41 41
42 42 MAJOR = 1
43 43 MINOR = 0
44   - TINY = 3
  44 + TINY = 4
45 45
46 46 # The current version as a Version instance
47 47 CURRENT = new(MAJOR, MINOR, TINY)
1  rails/init.rb
... ... @@ -0,0 +1 @@
  1 +require "authlogic_openid"
6 test/test_helper.rb
@@ -45,11 +45,11 @@
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 @@ def activate_authlogic
69 69 end
70 70
71 71 def controller
72   - @controller ||= Authlogic::TestCase::ControllerAdapter.new(ActionController.new)
  72 + @controller ||= Authlogic::ControllerAdapters::RailsAdapter.new(ActionController.new)
73 73 end
74 74
75 75 def redirecting_to_yahoo?

0 comments on commit 8a8c772

Please sign in to comment.
Something went wrong with that request. Please try again.