Class: Foobara::Auth::VerifyToken
- Defined in:
- foobara-auth-0.0.9/src/verify_token.rb
Defined Under Namespace
Classes: ExpiredTokenError, InactiveTokenError
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
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
#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions
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.
48 49 50 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 48 def secret @secret end |
#token_id ⇒ Object
Returns the value of attribute token_id.
48 49 50 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 48 def token_id @token_id end |
#token_record_to_verify_against ⇒ Object
51 52 53 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 51 def token_record_to_verify_against @token_record_to_verify_against || token_record end |
#verified ⇒ Object
Returns the value of attribute verified.
48 49 50 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 48 def verified @verified end |
Instance Method Details
#determine_token_id_and_hashed_secret ⇒ Object
59 60 61 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 59 def determine_token_id_and_hashed_secret self.token_id, self.secret = token_string.split("_") end |
#execute ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 34 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
63 64 65 66 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 63 def load_token_record self.token_record_to_verify_against = Types::Token.load(token_id) # TODO: handle no record found... end |
#token_record? ⇒ Boolean
55 56 57 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 55 def token_record? !!token_record end |
#validate_token_is_active ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 84 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
74 75 76 77 78 79 80 81 82 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 74 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
96 97 98 99 100 101 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 96 def verified_and_token_record { verified:, token_record: token_record_to_verify_against } end |
#verify_hashed_secret_against_token_record ⇒ Object
68 69 70 71 72 |
# File 'foobara-auth-0.0.9/src/verify_token.rb', line 68 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 |