Module: Authlogic::Session::OpenID
- Defined in:
- lib/authlogic/session/openid.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#authenticating_with_openid? ⇒ Boolean
Returns true if logging in with openid.
- #credentials_with_openid=(values) ⇒ Object
- #initialize_with_openid(*args) ⇒ Object
- #openid_verified? ⇒ Boolean
- #valid_openid? ⇒ Boolean
- #verify_openid? ⇒ Boolean
Class Method Details
.included(klass) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/authlogic/session/openid.rb', line 4 def self.included(klass) klass.class_eval do alias_method_chain :initialize, :openid alias_method_chain :credentials=, :openid alias_method_chain :create_configurable_methods!, :openid before_validation :valid_openid? attr_accessor :openid_response end end |
Instance Method Details
#authenticating_with_openid? ⇒ Boolean
Returns true if logging in with openid. Credentials mean username and password.
27 28 29 |
# File 'lib/authlogic/session/openid.rb', line 27 def authenticating_with_openid? authenticating_with == :openid end |
#credentials_with_openid=(values) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/authlogic/session/openid.rb', line 19 def credentials_with_openid=(values) result = self.credentials_without_openid = values return result if openid_field.blank? || values.blank? || !values.is_a?(Hash) || values[:openid].blank? self.openid = values[:openid] result end |
#initialize_with_openid(*args) ⇒ Object
14 15 16 17 |
# File 'lib/authlogic/session/openid.rb', line 14 def initialize_with_openid(*args) initialize_without_openid(*args) self.authenticating_with = :openid if openid_verification_complete? end |
#openid_verified? ⇒ Boolean
35 36 37 |
# File 'lib/authlogic/session/openid.rb', line 35 def openid_verified? controller.params[:openid_complete] == "1" end |
#valid_openid? ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/authlogic/session/openid.rb', line 39 def valid_openid? return false if openid_field.blank? if openid_verification_complete? case openid_response.status when OpenID::Consumer::SUCCESS when OpenID::Consumer::CANCEL errors.add_to_base("OpenID authentication was cancelled.") when OpenID::Consumer::FAILURE errors.add_to_base("OpenID authentication failed.") when OpenID::Consumer::SETUP_NEEDED errors.add_to_Base("OpenID authentication needs setup.") end else if authenticating_with_openid? if send(openid_field).blank? errors.add(openid_field, "can not be blank") return false end unless search_for_record(find_by_openid_method, send(openid_field)) errors.add(openid_field, "did not match any records in our database") return false end begin self.openid_response = openid_consumer.begin(send(openid_field)) rescue OpenID::OpenIDError => e errors.add("The OpenID identifier #{send(openid_field)} could not be found: #{e}") return false end sregreq = OpenID::SReg::Request.new # required fields #sregreq.request_fields(['email','nickname'], true) # optional fields #sregreq.request_fields(['dob', 'fullname'], false) oidreq.add_extension(sregreq) oidreq.return_to_args["openid_complete"] = 1 end end end |
#verify_openid? ⇒ Boolean
31 32 33 |
# File 'lib/authlogic/session/openid.rb', line 31 def verify_openid? authenticating_with_openid? && controller.params[:openid_complete] != "1" end |