Class: Foobara::Auth::VerifyAccessToken

Inherits:
Command
  • Object
show all
Defined in:
foobara-auth-0.0.9/src/verify_access_token.rb

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Attributes included from CommandPatternImplementation::Concerns::Subcommands

#is_subcommand

Attributes included from CommandPatternImplementation::Concerns::Runtime

#exception, #outcome

Attributes included from CommandPatternImplementation::Concerns::Errors

#error_collection

Attributes included from CommandPatternImplementation::Concerns::Inputs

#inputs, #raw_inputs

Instance Method Summary collapse

Methods inherited from Command

install!, reset_all

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods included from CommandPatternImplementation::Concerns::Reflection

#initialize

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

#load_entities, #load_records

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

#state_machine

Methods included from CommandPatternImplementation::Concerns::Runtime

#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records

Methods included from CommandPatternImplementation::Concerns::Errors

#initialize

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

#inspect, truncating

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs

Instance Attribute Details

#failure_reasonObject

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

#headersObject

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

#payloadObject

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

#verifiedObject

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_tokenObject



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

#executeObject



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_secretObject



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_flagObject



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_headersObject



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