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
# 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

  search_results = conn.get("/owa/?ae=Dialog&t=AddressBook&ctx=1&sch=#{uid}").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

  @first_name = details.match(/<td[^>]*>First name<\/td><td[^>]*>([^<]*)/)[1]
  @last_name = details.match(/<td[^>]*>Last name<\/td><td[^>]*>([^<]*)/)[1]
  @name = "#{@first_name} #{@last_name}"
  super
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