Class: OmniAuth::Strategies::HttpBasic

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, name, endpoint = nil, headers = {}, &block) ⇒ HttpBasic

Returns a new instance of HttpBasic.



9
10
11
12
13
# File 'lib/omniauth/strategies/http_basic.rb', line 9

def initialize(app, name, endpoint = nil, headers = {}, &block)
  super
  @endpoint = endpoint
  @request_headers = headers
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



15
16
17
# File 'lib/omniauth/strategies/http_basic.rb', line 15

def endpoint
  @endpoint
end

#request_headersObject (readonly)

Returns the value of attribute request_headers.



15
16
17
# File 'lib/omniauth/strategies/http_basic.rb', line 15

def request_headers
  @request_headers
end

Instance Method Details

#callback_phaseObject



51
52
53
# File 'lib/omniauth/strategies/http_basic.rb', line 51

def callback_phase
  fail!(:invalid_credentials)
end

#get_credentialsObject



29
30
31
32
33
34
# File 'lib/omniauth/strategies/http_basic.rb', line 29

def get_credentials
  OmniAuth::Form.build(:title => title) do
    text_field 'Username', 'username'
    password_field 'Password', 'password'
  end.to_response
end

#performObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/omniauth/strategies/http_basic.rb', line 36

def perform
  @response = perform_authentication(endpoint)
  @env['omniauth.auth'] = auth_hash
  @env['REQUEST_METHOD'] = 'GET'
  @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback"

  call_app!
rescue RestClient::Request::Unauthorized => e
  fail!(:invalid_credentials, e)
end

#perform_authentication(uri, headers = request_headers) ⇒ Object



47
48
49
# File 'lib/omniauth/strategies/http_basic.rb', line 47

def perform_authentication(uri, headers = request_headers)
  RestClient.get(uri, headers)
end

#request_phaseObject



17
18
19
20
21
22
23
# File 'lib/omniauth/strategies/http_basic.rb', line 17

def request_phase
  if env['REQUEST_METHOD'] == 'GET'
    get_credentials
  else
    perform
  end
end

#titleObject



25
26
27
# File 'lib/omniauth/strategies/http_basic.rb', line 25

def title
  name.split('_').map{|s| s.capitalize}.join(' ')
end