Skip to content

Commit

Permalink
Handles the issues caused by autoregistration with OpenID 2.0 directe…
Browse files Browse the repository at this point in the history
…d identity.
  • Loading branch information
pelle committed Oct 1, 2009
1 parent 1b714a6 commit 0b07998
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/authlogic_openid/session.rb
Expand Up @@ -70,10 +70,21 @@ def openid_identifier=(value)
# error. # error.
def save(&block) def save(&block)
begin begin
block = nil if !openid_identifier.blank? if beginning_authenticating_with_openid?
super(&block) block = nil
super &block
else
super do |result|
if block
# don't call the block if we have already rendered or redirected elsewhere
block.call(result) unless controller.send(:performed?)
end
end
end
rescue AuthlogicOpenid::Session::OpenIDNotFoundException rescue AuthlogicOpenid::Session::OpenIDNotFoundException
# The openid library sets a bunch of sessions fields we need to clear up
controller.send( :open_id_consumer).send( :cleanup_session) controller.send( :open_id_consumer).send( :cleanup_session)
# The user object won't start the discovery correctly if open_id_complete is set
controller.params[:open_id_complete]=nil #we need to start a fresh for autocomplete controller.params[:open_id_complete]=nil #we need to start a fresh for autocomplete
self.attempted_record = klass.new :openid_identifier=>openid_identifier self.attempted_record = klass.new :openid_identifier=>openid_identifier
attempted_record.save do |result| attempted_record.save do |result|
Expand All @@ -87,6 +98,11 @@ def authenticating_with_openid?
attempted_record.nil? && errors.empty? && (!openid_identifier.blank? || (controller.params[:open_id_complete] && controller.params[:for_session])) attempted_record.nil? && errors.empty? && (!openid_identifier.blank? || (controller.params[:open_id_complete] && controller.params[:for_session]))
end end


# We are starting the openid process
def beginning_authenticating_with_openid?
attempted_record.nil? && errors.empty? && (!openid_identifier.blank? )
end

def find_by_openid_identifier_method def find_by_openid_identifier_method
self.class.find_by_openid_identifier_method self.class.find_by_openid_identifier_method
end end
Expand All @@ -98,10 +114,11 @@ def auto_register?
def validate_by_openid def validate_by_openid
self.remember_me = controller.params[:remember_me] == "true" if controller.params.key?(:remember_me) self.remember_me = controller.params[:remember_me] == "true" if controller.params.key?(:remember_me)
if openid_complete? if openid_complete?
self.openid_identifier ||= controller.params["openid.identity"] self.openid_identifier ||= controller.params["openid.claimed_id"]||controller.params["openid.identity"]
self.attempted_record = klass.send(find_by_openid_identifier_method, openid_identifier) self.attempted_record = klass.send(find_by_openid_identifier_method, openid_identifier)
if !attempted_record if !attempted_record
if auto_register? if auto_register?
# We raise an exception here so we don't have to deal with all the other issues here
raise OpenIDNotFoundException raise OpenIDNotFoundException
else else
errors.add(:openid_identifier, "did not match any users in our database, have you set up your account to use OpenID?") errors.add(:openid_identifier, "did not match any users in our database, have you set up your account to use OpenID?")
Expand Down

0 comments on commit 0b07998

Please sign in to comment.