Class: Nucleus::Adapters::HttpBasicAuthClient
- Inherits:
-
AuthClient
- Object
- AuthClient
- Nucleus::Adapters::HttpBasicAuthClient
- Defined in:
- lib/nucleus/core/adapter_extensions/auth/http_basic_auth_client.rb
Overview
Implementation of the AuthClient that works with the HTTP basic authentication.
Instance Attribute Summary
Attributes inherited from AuthClient
Instance Method Summary collapse
- #auth_header ⇒ Object
- #authenticate(username, password) ⇒ Object
-
#initialize(check_certificates = true) {|verify_ssl, username, password| ... } ⇒ HttpBasicAuthClient
constructor
Create a new instance of an HttpBasicAuthClient.
Methods inherited from AuthClient
Constructor Details
#initialize(check_certificates = true) {|verify_ssl, username, password| ... } ⇒ HttpBasicAuthClient
Create a new instance of an Nucleus::Adapters::HttpBasicAuthClient. false if they are to be ignored (e.g. when using self-signed certificates in development environments) must check if the combination of username and password is accepted by the endpoint. including the authentication header to be tested false if an error occurred, e.g. with bad credentials
14 15 16 17 |
# File 'lib/nucleus/core/adapter_extensions/auth/http_basic_auth_client.rb', line 14 def initialize(check_certificates = true, &verification) @verification = verification super(check_certificates) end |
Instance Method Details
#auth_header ⇒ Object
30 31 32 33 34 |
# File 'lib/nucleus/core/adapter_extensions/auth/http_basic_auth_client.rb', line 30 def auth_header fail Errors::EndpointAuthenticationError, 'Authentication client was not authenticated yet' unless @packed_credentials { 'Authorization' => "Basic #{@packed_credentials}" } end |
#authenticate(username, password) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/nucleus/core/adapter_extensions/auth/http_basic_auth_client.rb', line 20 def authenticate(username, password) packed_credentials = ["#{username}:#{password}"].pack('m*').gsub(/\n/, '') valid = @verification.call(verify_ssl, 'Authorization' => "Basic #{packed_credentials}") fail Errors::EndpointAuthenticationError, 'Authentication failed, credentials seem to be invalid' unless valid # verification passed, credentials are valid @packed_credentials = packed_credentials self end |