Class: Authorio::Session
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Authorio::Session
- Defined in:
- app/models/authorio/session.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.find_by_cookie(cookie) ⇒ Object
-
To guard against timing attacks, we lookup tokens based on a separate selector attribute and compare them using a secure time-constant comparison method
21 22 23 24 25 26 27 |
# File 'app/models/authorio/session.rb', line 21 def self.() selector, _token = .split(':') session = find_by selector: selector raise Authorio::Exceptions::SessionReplayAttack.new, session unless session.() session end |
Instance Method Details
#as_cookie ⇒ Object
39 40 41 |
# File 'app/models/authorio/session.rb', line 39 def "#{selector}:#{token}" end |
#expired? ⇒ Boolean
35 36 37 |
# File 'app/models/authorio/session.rb', line 35 def expired? expires_at < Time.now end |
#matches_cookie?(cookie) ⇒ Boolean
29 30 31 32 33 |
# File 'app/models/authorio/session.rb', line 29 def () _selector, token = .split(':') = Digest::SHA256.hexdigest token !expired? && ActiveSupport::SecurityUtils.secure_compare(, hashed_token) end |