Class: OmniAuth::Strategies::LDAP

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/contour/fixes/omniauth.rb

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject

Raises:

  • (MissingCredentialsError)


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/contour/fixes/omniauth.rb', line 95

def callback_phase
  failure_temp_path = "#{@env['SCRIPT_NAME']}/#{OmniAuth.config.path_prefix.split('/').last}/failure?message=invalid_credentials" # Added
  bind_dn = "#{request['domain'] + '\\' unless request['domain'].blank?}#{request['username']}" # Added
  @options[:bind_dn] = bind_dn if @options[:bind_dn].blank? # Added
  @adaptor = OmniAuth::LDAP::Adaptor.new @options

  raise MissingCredentialsError.new("Missing login credentials") if request['username'].nil? || request['password'].nil?
  begin
    @ldap_user_info = @adaptor.bind_as(base: @adaptor.base, username: bind_dn, :password => request['password']) # Modified

    # return fail!(:invalid_credentials) if !@ldap_user_info
    return redirect failure_temp_path if !@ldap_user_info

    @user_info = self.class.map_user(@@config, @ldap_user_info)
    super
  rescue Exception => e
    # return fail!(:ldap_error, e)
    return redirect failure_temp_path
  end
end

#request_phaseObject



86
87
88
89
90
91
92
93
# File 'lib/contour/fixes/omniauth.rb', line 86

def request_phase
  OmniAuth::LDAP::Adaptor.validate @options
  f = OmniAuth::Form.new(:title => (options[:title] || "LDAP Authentication"), :url => "#{@env['SCRIPT_NAME']}" + callback_path)
  f.hidden_field 'domain', options[:domain] # Added to allow domains from option
  f.text_field 'Login', 'username'
  f.password_field 'Password', 'password'
  f.to_response
end