Class: Merb::Authentication::Strategies::Basic::OpenID
- Inherits:
-
Base
- Object
- Merb::Authentication::Strategy
- Base
- Merb::Authentication::Strategies::Basic::OpenID
- Defined in:
- lib/merb-auth-more/strategies/basic/openid.rb
Instance Method Summary collapse
-
#find_user_by_identity_url(url) ⇒ Object
Overwrite this to support an ORM other than DataMapper.
- #on_cancel!(response) ⇒ Object
-
#on_failure!(response) ⇒ Object
Overwrite the on_failure! method with the required behavior for failed logins.
- #on_setup_needed!(response) ⇒ Object
-
#on_success!(response, sreg_response) ⇒ Object
Overwrite the on_success! method with the required behavior for successful logins.
-
#openid_store ⇒ Object
Overwrite this method to set your store.
- #required_reg_fields ⇒ Object
- #run! ⇒ Object
Methods inherited from Base
#login_param, login_param, password_param, #password_param
Instance Method Details
#find_user_by_identity_url(url) ⇒ Object
Overwrite this to support an ORM other than DataMapper
110 111 112 |
# File 'lib/merb-auth-more/strategies/basic/openid.rb', line 110 def find_user_by_identity_url(url) user_class.first(:identity_url => url) end |
#on_cancel!(response) ⇒ Object
95 96 97 98 99 |
# File 'lib/merb-auth-more/strategies/basic/openid.rb', line 95 def on_cancel!(response) request.session.authentication.errors.clear! request.session.authentication.errors.add(:openid, 'OpenID rejected our request') nil end |
#on_failure!(response) ⇒ Object
Overwrite the on_failure! method with the required behavior for failed logins
79 80 81 82 83 |
# File 'lib/merb-auth-more/strategies/basic/openid.rb', line 79 def on_failure!(response) session.authentication.errors.clear! session.authentication.errors.add(:openid, 'OpenID verification failed, maybe the provider is down? Or the session timed out') nil end |
#on_setup_needed!(response) ⇒ Object
87 88 89 90 91 |
# File 'lib/merb-auth-more/strategies/basic/openid.rb', line 87 def on_setup_needed!(response) request.session.authentication.errors.clear! request.session.authentication.errors.add(:openid, 'OpenID does not seem to be configured correctly') nil end |
#on_success!(response, sreg_response) ⇒ Object
Overwrite the on_success! method with the required behavior for successful logins
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/merb-auth-more/strategies/basic/openid.rb', line 64 def on_success!(response, sreg_response) if user = find_user_by_identity_url(response.identity_url) user else request.session[:'openid.url'] = response.identity_url required_reg_fields.each do |f| session[:"openid.#{f}"] = sreg_response.data[f] if sreg_response.data[f] end if sreg_response redirect!(Merb::Router.url(:signup)) end end |
#openid_store ⇒ Object
Overwrite this method to set your store
117 118 119 |
# File 'lib/merb-auth-more/strategies/basic/openid.rb', line 117 def openid_store ::OpenID::Store::Filesystem.new("#{Merb.root}/tmp/openid") end |
#required_reg_fields ⇒ Object
103 104 105 |
# File 'lib/merb-auth-more/strategies/basic/openid.rb', line 103 def required_reg_fields ['nickname', 'email'] end |
#run! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/merb-auth-more/strategies/basic/openid.rb', line 28 def run! if request.params[:'openid.mode'] response = consumer.complete(request.send(:query_params), "#{request.protocol}://#{request.host}" + request.path) case response.status.to_s when 'success' sreg_response = ::OpenID::SReg::Response.from_success_response(response) result = on_success!(response, sreg_response) Merb.logger.info "\n\n#{result.inspect}\n\n" result when 'failure' on_failure!(response) when 'setup_needed' on_setup_needed!(response) when 'cancel' on_cancel!(response) end elsif identity_url = params[:openid_url] begin openid_request = consumer.begin(identity_url) openid_reg = ::OpenID::SReg::Request.new openid_reg.request_fields(required_reg_fields) openid_request.add_extension(openid_reg) redirect_to = "#{request.protocol}://#{request.host}#{Merb::Router.url(:openid)}" redirect!(openid_request.redirect_url("#{request.protocol}://#{request.host}", redirect_to)) rescue ::OpenID::OpenIDError => e request.session.authentication.errors.clear! request.session.authentication.errors.add(:openid, 'The OpenID verification failed') nil end end end |