Class: OmniAuth::Strategies::OWA

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

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/omniauth/strategies/owa.rb', line 18

def callback_phase
  uid, password = request.params.values_at "uid", "password"

  conn = Faraday.new url: options.base_url
  conn.basic_auth uid, password

  response = conn.get("/owa/?ae=Dialog&t=AddressBook&ctx=1&sch=#{uid}")
  return fail!(:invalid_credentials) unless response.success?
  search_results = response.body
  id = search_results.match(/<h1><a href="#" id="([^"]+)"/)[1]
  details = conn.get("/owa/?ae=Item&t=AD.RecipientType.User&id=#{CGI.escape id}").body

  @info = {}
  @info[:first_name] = details.match(/<td[^>]*>First name<\/td><td[^>]*>([^<]*)/)[1]
  @info[:last_name] = details.match(/<td[^>]*>Last name<\/td><td[^>]*>([^<]*)/)[1]
  @info[:email] = details.match(/<td[^>]*>E-mail<\/td><td[^>]*>([^<]*)/)[1]
  @info[:name] = "#{@info[:first_name]} #{@info[:last_name]}"
  super
rescue
  fail! :internal_error
end

#request_phaseObject



10
11
12
13
14
15
16
# File 'lib/omniauth/strategies/owa.rb', line 10

def request_phase
  form = OmniAuth::Form.new url: callback_path
  form.text_field "Username", :uid
  form.password_field "Password", :password
  form.button "Log in"
  form.to_response
end