Class: Nucleus::Adapters::TokenAuthClient
- Inherits:
-
AuthClient
- Object
- AuthClient
- Nucleus::Adapters::TokenAuthClient
- Defined in:
- lib/nucleus/core/adapter_extensions/auth/token_auth_client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
Attributes inherited from AuthClient
Instance Method Summary collapse
- #auth_header ⇒ Object
- #authenticate(username, password) ⇒ Object
-
#initialize(check_certificates = true) {|verify_ssl, username, password| ... } ⇒ TokenAuthClient
constructor
Create a new instance of an TokenAuthClient.
Methods inherited from AuthClient
Constructor Details
#initialize(check_certificates = true) {|verify_ssl, username, password| ... } ⇒ TokenAuthClient
Create a new instance of an Nucleus::Adapters::TokenAuthClient. false if they are to be ignored (e.g. when using self-signed certificates in development environments) must provide the API token, usually retrieved from an HTTP call to the endpoint. false if they are to be ignored (e.g. when using self-signed certificates in development environments) nil if authentication failed, e.g. due to bad credentials
17 18 19 20 |
# File 'lib/nucleus/core/adapter_extensions/auth/token_auth_client.rb', line 17 def initialize(check_certificates = true, &token_parser) @token_parser = token_parser super(check_certificates) end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
4 5 6 |
# File 'lib/nucleus/core/adapter_extensions/auth/token_auth_client.rb', line 4 def api_token @api_token end |
Instance Method Details
#auth_header ⇒ Object
30 31 32 33 |
# File 'lib/nucleus/core/adapter_extensions/auth/token_auth_client.rb', line 30 def auth_header fail Errors::EndpointAuthenticationError, 'Authentication client was not authenticated yet' unless @api_token { 'Authorization' => "Bearer #{api_token}" } end |
#authenticate(username, password) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/nucleus/core/adapter_extensions/auth/token_auth_client.rb', line 22 def authenticate(username, password) token = @token_parser.call(verify_ssl, username, password) fail Errors::EndpointAuthenticationError, 'Authentication failed, credentials seem to be invalid' unless token # verification passed, credentials are valid @api_token = token self end |