Class: Foobara::Auth::VerifyAccessToken
- Defined in:
- foobara-auth-0.0.9/src/verify_access_token.rb
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary collapse
-
#failure_reason ⇒ Object
Returns the value of attribute failure_reason.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#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
- #decode_access_token ⇒ Object
- #execute ⇒ Object
- #jwt_secret ⇒ Object
- #set_verified_flag ⇒ Object
- #verified_flag_payload_and_headers ⇒ 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
#failure_reason ⇒ Object
Returns the value of attribute failure_reason.
25 26 27 |
# File 'foobara-auth-0.0.9/src/verify_access_token.rb', line 25 def failure_reason @failure_reason end |
#headers ⇒ Object
Returns the value of attribute headers.
25 26 27 |
# File 'foobara-auth-0.0.9/src/verify_access_token.rb', line 25 def headers @headers end |
#payload ⇒ Object
Returns the value of attribute payload.
25 26 27 |
# File 'foobara-auth-0.0.9/src/verify_access_token.rb', line 25 def payload @payload end |
#verified ⇒ Object
Returns the value of attribute verified.
25 26 27 |
# File 'foobara-auth-0.0.9/src/verify_access_token.rb', line 25 def verified @verified end |
Instance Method Details
#decode_access_token ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'foobara-auth-0.0.9/src/verify_access_token.rb', line 27 def decode_access_token self.payload, self.headers = JWT.decode(access_token, jwt_secret) rescue JWT::VerificationError self.failure_reason = "cannot_verify" rescue JWT::ExpiredSignature self.failure_reason = "expired" rescue JWT::DecodeError self.failure_reason = "invalid" end |
#execute ⇒ Object
18 19 20 21 22 23 |
# File 'foobara-auth-0.0.9/src/verify_access_token.rb', line 18 def execute decode_access_token set_verified_flag verified_flag_payload_and_headers end |
#jwt_secret ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'foobara-auth-0.0.9/src/verify_access_token.rb', line 50 def jwt_secret jwt_secret_text = ENV.fetch("JWT_SECRET", nil) unless jwt_secret_text # :nocov: raise "You must set the JWT_SECRET environment variable" # :nocov: end jwt_secret_text end |
#set_verified_flag ⇒ Object
37 38 39 |
# File 'foobara-auth-0.0.9/src/verify_access_token.rb', line 37 def set_verified_flag self.verified = !failure_reason end |
#verified_flag_payload_and_headers ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'foobara-auth-0.0.9/src/verify_access_token.rb', line 41 def verified_flag_payload_and_headers { verified:, failure_reason:, payload:, headers: } end |