Class: OmniAuth::Strategies::HttpBasic
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::HttpBasic
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/http_basic.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#request_headers ⇒ Object
readonly
Returns the value of attribute request_headers.
Instance Method Summary collapse
- #callback_phase ⇒ Object
- #get_credentials ⇒ Object
-
#initialize(app, name, endpoint = nil, headers = {}, &block) ⇒ HttpBasic
constructor
A new instance of HttpBasic.
- #perform ⇒ Object
- #perform_authentication(uri, headers = request_headers) ⇒ Object
- #request_phase ⇒ Object
- #title ⇒ Object
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
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
15 16 17 |
# File 'lib/omniauth/strategies/http_basic.rb', line 15 def endpoint @endpoint end |
#request_headers ⇒ Object (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_phase ⇒ Object
51 52 53 |
# File 'lib/omniauth/strategies/http_basic.rb', line 51 def callback_phase fail!(:invalid_credentials) end |
#get_credentials ⇒ Object
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 |
#perform ⇒ Object
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_phase ⇒ Object
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 |
#title ⇒ Object
25 26 27 |
# File 'lib/omniauth/strategies/http_basic.rb', line 25 def title name.split('_').map{|s| s.capitalize}.join(' ') end |