Class: ApiKeys::Services::Authenticator::Result

Inherits:
Struct
  • Object
show all
Defined in:
lib/api_keys/services/authenticator.rb

Overview

Result object for authentication attempts.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key

Returns:

  • (Object)

    the current value of api_key



24
25
26
# File 'lib/api_keys/services/authenticator.rb', line 24

def api_key
  @api_key
end

#error_codeObject

Returns the value of attribute error_code

Returns:

  • (Object)

    the current value of error_code



24
25
26
# File 'lib/api_keys/services/authenticator.rb', line 24

def error_code
  @error_code
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



24
25
26
# File 'lib/api_keys/services/authenticator.rb', line 24

def message
  @message
end

#success?Object

Returns the value of attribute success?

Returns:

  • (Object)

    the current value of success?



24
25
26
# File 'lib/api_keys/services/authenticator.rb', line 24

def success?
  @success?
end

Class Method Details

.failure(error_code:, message:, api_key: nil) ⇒ Object

api_key is present when the key WAS identified and a policy check refused it (environment isolation, request restrictions): the after_authentication callback then reports WHICH key was refused, exactly as it already does for scope refusals. Lookup failures have no key to name, so they leave it nil.



34
35
36
# File 'lib/api_keys/services/authenticator.rb', line 34

def self.failure(error_code:, message:, api_key: nil)
  new(success?: false, error_code: error_code, message: message, api_key: api_key)
end

.success(api_key) ⇒ Object



25
26
27
# File 'lib/api_keys/services/authenticator.rb', line 25

def self.success(api_key)
  new(success?: true, api_key: api_key)
end

Instance Method Details

#inspectObject Also known as: to_s

Do not delegate to Struct's default inspection: it recursively inspects the Active Record object and can expose token digests or public tokens.



40
41
42
# File 'lib/api_keys/services/authenticator.rb', line 40

def inspect
  "#<#{self.class.name} success?=#{success?.inspect} api_key_id=#{api_key&.id.inspect} error_code=#{error_code.inspect}>"
end