Class: QuoVadis::Token
- Inherits:
-
Object
show all
- Extended by:
- Hmacable
- Defined in:
- app/models/quo_vadis/token.rb
Class Method Summary
collapse
Methods included from Hmacable
compute_hmac, timing_safe_eql?
Class Method Details
.find_account(token) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/models/quo_vadis/token.rb', line 15
def find_account(token)
provided_public_data, provided_hmac = token.split '--'
id, expires_at = provided_public_data.split '-'
account = Account.find id
data = data_for_hmac provided_public_data, account
actual_hmac = compute_hmac data
return nil unless timing_safe_eql? provided_hmac, actual_hmac
return nil if expires_at.to_i < Time.current.to_i
account
rescue
nil
end
|
.generate(account) ⇒ Object
9
10
11
12
13
|
# File 'app/models/quo_vadis/token.rb', line 9
def generate(account)
public_data = "#{account.id}-#{expires_at}"
data = data_for_hmac public_data, account
"#{public_data}--#{compute_hmac(data)}"
end
|