Class: Foobara::Auth::AuthenticateWithApiKey
- Defined in:
- foobara-auth-0.0.13/src/authenticate_with_api_key.rb
Defined Under Namespace
Classes: ApiKeyDoesNotExistError, InvalidApiKeyError
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary collapse
-
#api_key_id ⇒ Object
Returns the value of attribute api_key_id.
-
#api_key_record ⇒ Object
Returns the value of attribute api_key_record.
-
#api_key_secret ⇒ Object
Returns the value of attribute api_key_secret.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#user ⇒ Object
Returns the value of attribute user.
Attributes included from CommandPatternImplementation::Concerns::Subcommands
Attributes included from CommandPatternImplementation::Concerns::Runtime
Attributes included from CommandPatternImplementation::Concerns::Errors
Attributes included from CommandPatternImplementation::Concerns::Inputs
Instance Method Summary collapse
- #determine_api_key_id_and_secret ⇒ Object
- #execute ⇒ Object
- #load_api_key_record ⇒ Object
- #load_user ⇒ Object
- #user_and_credential ⇒ Object
- #verify_api_key ⇒ Object
Methods inherited from Command
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Methods included from CommandPatternImplementation::Concerns::Reflection
Methods included from CommandPatternImplementation::Concerns::DomainMappers
#domain_map, #domain_map!, #run_mapped_subcommand!
Methods included from CommandPatternImplementation::Concerns::Subcommands
#run_subcommand!, #subcommand?
Methods included from CommandPatternImplementation::Concerns::Entities
Methods included from CommandPatternImplementation::Concerns::Transactions
Methods included from NestedTransactionable
#auto_detect_current_transactions, #commit_transaction, #commit_transaction_if_open, #open_transaction, #opened_transactions, #relevant_entity_classes, relevant_entity_classes_for_type, #relevant_entity_classes_for_type, #rollback_transaction, #transactions, #use_transaction
Methods included from CommandPatternImplementation::Concerns::StateMachine
Methods included from CommandPatternImplementation::Concerns::Runtime
#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records
Methods included from CommandPatternImplementation::Concerns::Errors
Methods included from CommandPatternImplementation::Concerns::Inputs
#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?
Methods included from TruncatedInspect
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs
Instance Attribute Details
#api_key_id ⇒ Object
Returns the value of attribute api_key_id.
37 38 39 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 37 def api_key_id @api_key_id end |
#api_key_record ⇒ Object
Returns the value of attribute api_key_record.
37 38 39 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 37 def api_key_record @api_key_record end |
#api_key_secret ⇒ Object
Returns the value of attribute api_key_secret.
37 38 39 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 37 def api_key_secret @api_key_secret end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
37 38 39 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 37 def expires_at @expires_at end |
#user ⇒ Object
Returns the value of attribute user.
37 38 39 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 37 def user @user end |
Instance Method Details
#determine_api_key_id_and_secret ⇒ Object
39 40 41 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 39 def determine_api_key_id_and_secret self.api_key_id, self.api_key_secret = api_key.split("_") end |
#execute ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 27 def execute determine_api_key_id_and_secret load_api_key_record verify_api_key load_user user_and_credential end |
#load_api_key_record ⇒ Object
43 44 45 46 47 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 43 def load_api_key_record self.api_key_record = Types::Token.load(api_key_id) rescue Foobara::Entity::NotFoundError add_runtime_error(ApiKeyDoesNotExistError) end |
#load_user ⇒ Object
57 58 59 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 57 def load_user self.user ||= Types::User.that_owns(api_key_record, "api_keys") end |
#user_and_credential ⇒ Object
61 62 63 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 61 def user_and_credential [user, api_key_record] end |
#verify_api_key ⇒ Object
49 50 51 52 53 54 55 |
# File 'foobara-auth-0.0.13/src/authenticate_with_api_key.rb', line 49 def verify_api_key valid = run_subcommand!(VerifyToken, token_string: api_key) unless valid[:verified] add_runtime_error(InvalidApiKeyError) end end |