Class: Foobara::Auth::VerifyToken
- Inherits:
-
Command
- Object
- Command
- Foobara::Auth::VerifyToken
show all
- Defined in:
- foobara-auth-0.1.1/src/verify_token.rb
Defined Under Namespace
Classes: ExpiredTokenError, InactiveTokenError, TokenDoesNotExistError
Constant Summary
TruncatedInspect::MAX_LENGTH
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Command
install!
#inspect, truncating
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Instance Attribute Details
#secret ⇒ Object
Returns the value of attribute secret.
53
54
55
|
# File 'src/verify_token.rb', line 53
def secret
@secret
end
|
#token_id ⇒ Object
Returns the value of attribute token_id.
53
54
55
|
# File 'src/verify_token.rb', line 53
def token_id
@token_id
end
|
#token_record_to_verify_against ⇒ Object
56
57
58
|
# File '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 'src/verify_token.rb', line 53
def verified
@verified
end
|
Instance Method Details
#determine_token_id_and_hashed_secret ⇒ Object
64
65
66
|
# File '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 '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
#token_record? ⇒ Boolean
60
61
62
|
# File '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 '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 '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 '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 '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
|