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.
Instance Method Summary collapse
- #callback_phase ⇒ Object
- #identity ⇒ Object
- #model ⇒ Object
- #on_registration_path? ⇒ Boolean
- #other_phase ⇒ Object
- #registration_form ⇒ Object
- #registration_path ⇒ Object
- #registration_phase ⇒ Object
- #request_phase ⇒ Object
Instance Method Details
#callback_phase ⇒ Object
30 31 32 33 |
# File 'lib/omniauth/strategies/identity.rb', line 30 def callback_phase return fail!(:invalid_credentials) unless identity super end |
#identity ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/omniauth/strategies/identity.rb', line 88 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
98 99 100 |
# File 'lib/omniauth/strategies/identity.rb', line 98 def model [:model] || ::Identity end |
#on_registration_path? ⇒ Boolean
84 85 86 |
# File 'lib/omniauth/strategies/identity.rb', line 84 def on_registration_path? on_path?(registration_path) end |
#other_phase ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/omniauth/strategies/identity.rb', line 35 def other_phase if on_registration_path? if request.get? registration_form elsif request.post? registration_phase end else call_app! end end |
#registration_form ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/omniauth/strategies/identity.rb', line 47 def registration_form if [:on_registration] [:on_registration].call(self.env) else OmniAuth::Form.build(:title => 'Register Identity') do |f| [:fields].each do |field| f.text_field field.to_s.capitalize, field.to_s end f.password_field 'Password', 'password' f.password_field 'Confirm Password', 'password_confirmation' end.to_response end end |
#registration_path ⇒ Object
80 81 82 |
# File 'lib/omniauth/strategies/identity.rb', line 80 def registration_path [:registration_path] || "#{path_prefix}/#{name}/register" end |
#registration_phase ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/omniauth/strategies/identity.rb', line 61 def registration_phase attributes = ([:fields] + [:password, :password_confirmation]).inject({}){|h,k| h[k] = request[k.to_s]; h} @identity = model.create(attributes) if @identity.persisted? env['PATH_INFO'] = callback_path callback_phase else if [:on_failed_registration] self.env['omniauth.identity'] = @identity [:on_failed_registration].call(self.env) else registration_form end end end |
#request_phase ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/omniauth/strategies/identity.rb', line 15 def request_phase if [:on_login] [:on_login].call(self.env) else OmniAuth::Form.build( :title => ([:title] || "Identity Verification"), :url => callback_path ) do |f| f.text_field 'Login', 'auth_key' f.password_field 'Password', 'password' f.html "<p align='center'><a href='#{registration_path}'>Create an Identity</a></p>" end.to_response end end |