Class: Foobara::Auth::VerifyToken
- Defined in:
- foobara-auth-0.0.13/src/verify_token.rb
Defined Under Namespace
Classes: ExpiredTokenError, InactiveTokenError, TokenDoesNotExistError
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary collapse
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#token_id ⇒ Object
Returns the value of attribute token_id.
- #token_record_to_verify_against ⇒ Object
-
#verified ⇒ Object
Returns the value of attribute verified.
Attributes included from CommandPatternImplementation::Concerns::Subcommands
Attributes included from CommandPatternImplementation::Concerns::Runtime
#exception, #outcome, #raw_result
Attributes included from CommandPatternImplementation::Concerns::Errors
Attributes included from CommandPatternImplementation::Concerns::Inputs
Instance Method Summary collapse
- #determine_token_id_and_hashed_secret ⇒ Object
- #execute ⇒ Object
- #load_token_record ⇒ Object
- #token_record? ⇒ Boolean
- #validate_token_is_active ⇒ Object
- #validate_token_is_not_expired ⇒ Object
- #verified_and_token_record ⇒ Object
- #verify_hashed_secret_against_token_record ⇒ 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, with_needed_transactions_for_type
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
#secret ⇒ Object
Returns the value of attribute secret.
53 54 55 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 53 def secret @secret end |
#token_id ⇒ Object
Returns the value of attribute token_id.
53 54 55 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 53 def token_id @token_id end |
#token_record_to_verify_against ⇒ Object
56 57 58 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 56 def token_record_to_verify_against @token_record_to_verify_against || token_record end |
#verified ⇒ Object
Returns the value of attribute verified.
53 54 55 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 53 def verified @verified end |
Instance Method Details
#determine_token_id_and_hashed_secret ⇒ Object
64 65 66 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 64 def determine_token_id_and_hashed_secret self.token_id, self.secret = token_string.split("_") end |
#execute ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 39 def execute determine_token_id_and_hashed_secret unless token_record? load_token_record end validate_token_is_active validate_token_is_not_expired verify_hashed_secret_against_token_record verified_and_token_record end |
#load_token_record ⇒ Object
68 69 70 71 72 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 68 def load_token_record self.token_record_to_verify_against = Types::Token.load(token_id) rescue Entity::NotFoundError add_runtime_error(TokenDoesNotExistError) end |
#token_record? ⇒ Boolean
60 61 62 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 60 def token_record? !!token_record end |
#validate_token_is_active ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 90 def validate_token_is_active unless token_record_to_verify_against.active? add_runtime_error( InactiveTokenError.new( context: { state: token_record_to_verify_against.state_machine.current_state } ) ) end end |
#validate_token_is_not_expired ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 80 def validate_token_is_not_expired if token_record_to_verify_against.expires_at&.<(Time.now) Types::Token.transaction(mode: :open_nested) do token = Types::Token.load(token_record_to_verify_against.id) token.expire! end add_runtime_error(ExpiredTokenError) end end |
#verified_and_token_record ⇒ Object
102 103 104 105 106 107 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 102 def verified_and_token_record { verified:, token_record: token_record_to_verify_against } end |
#verify_hashed_secret_against_token_record ⇒ Object
74 75 76 77 78 |
# File 'foobara-auth-0.0.13/src/verify_token.rb', line 74 def verify_hashed_secret_against_token_record hashed_secret = token_record_to_verify_against.hashed_secret self.verified = run_subcommand!(VerifySecret, secret:, hashed_secret:) end |