Class: OmniAuth::Strategies::Identity
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::Identity
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/identity.rb
Overview
The identity strategy allows you to provide simple internal user authentication using the same process flow that you use for external OmniAuth providers.
Constant Summary collapse
- DEFAULT_REGISTRATION_FIELDS =
i[password password_confirmation].freeze
Instance Method Summary collapse
- #callback_phase ⇒ Object
- #identity ⇒ Object
- #model ⇒ Object
- #on_registration_path? ⇒ Boolean
- #other_phase ⇒ Object
- #registration_form(validation_message = nil) ⇒ Object
- #registration_path ⇒ Object
- #registration_phase ⇒ Object
- #request_phase ⇒ Object
Instance Method Details
#callback_phase ⇒ Object
32 33 34 35 36 |
# File 'lib/omniauth/strategies/identity.rb', line 32 def callback_phase return fail!(:invalid_credentials) unless identity super end |
#identity ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/omniauth/strategies/identity.rb', line 99 def identity if [:locate_conditions].is_a? Proc conditions = instance_exec(request, &[:locate_conditions]) conditions.to_hash else conditions = [:locate_conditions].to_hash end @identity ||= model.authenticate(conditions, request['password']) end |
#model ⇒ Object
109 110 111 |
# File 'lib/omniauth/strategies/identity.rb', line 109 def model [:model] || ::Identity end |
#on_registration_path? ⇒ Boolean
95 96 97 |
# File 'lib/omniauth/strategies/identity.rb', line 95 def on_registration_path? on_path?(registration_path) end |
#other_phase ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/omniauth/strategies/identity.rb', line 38 def other_phase if [:enable_registration] && on_registration_path? if request.get? registration_form elsif request.post? registration_phase else call_app! end elsif [:enable_login] && on_request_path? # OmniAuth, by default, disables "GET" requests for security reasons. # This effectively disables omniauth-identity tool's login form feature. # Because it is disabled by default, and because enabling it would desecuritize all the other # OmniAuth strategies that may be implemented, we do not ask users to modify that setting. # Instead we hook in here in the "other_phase", with a config setting of our own: `enable_login` request_phase else call_app! end end |
#registration_form(validation_message = nil) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/omniauth/strategies/identity.rb', line 59 def registration_form( = nil) if [:on_registration] [:on_registration].call(env) else build_omniauth_registration_form().to_response end end |
#registration_path ⇒ Object
91 92 93 |
# File 'lib/omniauth/strategies/identity.rb', line 91 def registration_path [:registration_path] || "#{path_prefix}/#{name}/register" end |
#registration_phase ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/omniauth/strategies/identity.rb', line 67 def registration_phase attributes = ([:fields] + DEFAULT_REGISTRATION_FIELDS).each_with_object({}) do |k, h| h[k] = request[k.to_s] end if model.respond_to?(:column_names) && model.column_names.include?('provider') attributes.reverse_merge!(provider: 'identity') end if saving_instead_of_creating? @identity = model.new(attributes) env['omniauth.identity'] = @identity if !validating? || valid? @identity.save registration_result else registration_failure('Validation failed') end else deprecated_registration(attributes) end end |
#request_phase ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/omniauth/strategies/identity.rb', line 24 def request_phase if [:on_login] [:on_login].call(env) else build_omniauth_login_form.to_response end end |