Class: ApipieBindings::Authenticators::BasicAuthExternal
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #authenticate(original_request, _args) ⇒ Object
-
#initialize(user, password, authentication_url, auth_request_options = {}) ⇒ BasicAuthExternal
constructor
A new instance of BasicAuthExternal.
Methods inherited from Base
Constructor Details
#initialize(user, password, authentication_url, auth_request_options = {}) ⇒ BasicAuthExternal
Returns a new instance of BasicAuthExternal.
6 7 8 9 10 |
# File 'lib/apipie_bindings/authenticators/basic_auth_external.rb', line 6 def initialize(user, password, authentication_url, = {}) super(user, password) @authentication_url = authentication_url @auth_request_options = end |
Instance Method Details
#authenticate(original_request, _args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/apipie_bindings/authenticators/basic_auth_external.rb', line 12 def authenticate(original_request, _args) request = RestClient::Resource.new( @authentication_url, @auth_request_options.merge({ user: @user, password: @password }) ) request.get do |response, _, raw_response| if response.code == 401 raise RestClient::Unauthorized.new(response), 'External authentication did not pass.' end = raw_response['set-cookie'].split('; ')[0] @auth_cookie = original_request['Cookie'] = end original_request end |