Class: OmniAuth::Strategies::Identity

Inherits:
Object
  • Object
show all
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

Instance Method Details

#callback_phaseObject



23
24
25
26
# File 'lib/omniauth/strategies/identity.rb', line 23

def callback_phase
  return fail!(:invalid_credentials) unless identity
  super
end

#identityObject



77
78
79
# File 'lib/omniauth/strategies/identity.rb', line 77

def identity
  @identity ||= model.authenticate(request['auth_key'], request['password'])
end

#modelObject



81
82
83
# File 'lib/omniauth/strategies/identity.rb', line 81

def model
  options[:model] || ::Identity
end

#on_registration_path?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/omniauth/strategies/identity.rb', line 73

def on_registration_path?
  on_path?(registration_path)
end

#other_phaseObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/omniauth/strategies/identity.rb', line 28

def other_phase
  if on_registration_path?
    if request.get?
      registration_form
    elsif request.post?
      registration_phase
    end
  else
    call_app!
  end
end

#registration_formObject



40
41
42
43
44
45
46
47
48
# File 'lib/omniauth/strategies/identity.rb', line 40

def registration_form
  OmniAuth::Form.build(:title => 'Register Identity') do |f|
    options[: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

#registration_pathObject



69
70
71
# File 'lib/omniauth/strategies/identity.rb', line 69

def registration_path
  options[:registration_path] || "#{path_prefix}/#{name}/register"
end

#registration_phaseObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/omniauth/strategies/identity.rb', line 50

def registration_phase
  attributes = (options[: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 options[:on_failed_registration]
      self.env['omniauth.identity'] = @identity
      options[:on_failed_registration].call(self.env)
    else
      registration_form
    end
  end
end

#request_phaseObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/omniauth/strategies/identity.rb', line 12

def request_phase
  OmniAuth::Form.build(
    :title => (options[: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