Class: Foobara::AuthHttp::ApiKeyAuthenticator
- Inherits:
-
CommandConnector::Authenticator
- Object
- Value::Processor
- Value::Transformer
- CommandConnector::Authenticator
- Foobara::AuthHttp::ApiKeyAuthenticator
- Defined in:
- foobara-auth-http-0.0.7/src/foobara/auth_http/api_key_authenticator.rb
Instance Attribute Summary
Attributes inherited from Value::Processor
#created_in_namespace, #declaration_data, #parent_declaration_data
Class Method Summary collapse
Instance Method Summary collapse
- #applicable?(request) ⇒ Boolean
- #block ⇒ Object
-
#initialize(load_user: nil, relevant_entity_classes: Auth::Types::User) ⇒ ApiKeyAuthenticator
constructor
A new instance of ApiKeyAuthenticator.
- #relevant_entity_classes(request) ⇒ Object
Methods inherited from CommandConnector::Authenticator
#authenticate, #explanation, #symbol, #to_proc, #transform
Methods inherited from Value::Transformer
create, error_classes, foobara_manifest, #process_value, subclass, #transform
Methods inherited from Value::Processor
#always_applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, error_classes, #error_context, #error_message, #error_path, foobara_manifest, #foobara_manifest, #inspect, instance, #method_missing, #name, new_with_agnostic_args, #possible_errors, #priority, #process_outcome, #process_outcome!, #process_value, #process_value!, processor_name, requires_declaration_data?, requires_parent_declaration_data?, #respond_to_missing?, #runner, symbol
Methods included from IsManifestable
#foobara_domain, #foobara_manifest, #foobara_organization, #scoped_clear_caches
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Constructor Details
#initialize(load_user: nil, relevant_entity_classes: Auth::Types::User) ⇒ ApiKeyAuthenticator
Returns a new instance of ApiKeyAuthenticator.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'foobara-auth-http-0.0.7/src/foobara/auth_http/api_key_authenticator.rb', line 10 def initialize(load_user: nil, relevant_entity_classes: Auth::Types::User, **) @relevant_entity_classes = relevant_entity_classes if load_user @load_user = load_user end super( symbol: :api_key, explanation: "Expects an api key to be passed in the x-api-key header", ** ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::Value::Processor
Class Method Details
.load_user(&block) ⇒ Object
5 6 7 |
# File 'foobara-auth-http-0.0.7/src/foobara/auth_http/api_key_authenticator.rb', line 5 def load_user(**, &block) new(**, load_user: block) end |
Instance Method Details
#applicable?(request) ⇒ Boolean
24 25 26 |
# File 'foobara-auth-http-0.0.7/src/foobara/auth_http/api_key_authenticator.rb', line 24 def applicable?(request) request.headers.key?("x-api-key") end |
#block ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'foobara-auth-http-0.0.7/src/foobara/auth_http/api_key_authenticator.rb', line 28 def block @block ||= begin load_user_block = @load_user proc do api_key = headers["x-api-key"] outcome = Foobara::Auth::AuthenticateWithApiKey.run(api_key:) if outcome.success? user, credential = outcome.result if load_user_block user = load_user_block.call(user.id) end [user, credential] end end end end |
#relevant_entity_classes(request) ⇒ Object
50 51 52 53 54 |
# File 'foobara-auth-http-0.0.7/src/foobara/auth_http/api_key_authenticator.rb', line 50 def relevant_entity_classes(request) if applicable?(request) @relevant_entity_classes end end |