8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/lcp_ruby/api_tokens/verifier.rb', line 8
def self.verify(plaintext)
return nil if plaintext.nil? || plaintext.empty?
token_class = LcpRuby.registry.model_for("api_token")
return nil unless token_class
hash = TokenGenerator.hash(plaintext)
token = token_class.find_by(token_hash: hash)
return nil unless token
return nil unless ActiveSupport::SecurityUtils.secure_compare(token.token_hash.to_s, hash)
return nil if token.revoked_at.present?
return nil if token.expires_at.present? && token.expires_at < Date.current
touch_last_used_at(token)
user = token.user
return nil if user.nil?
return nil if user.respond_to?(:active?) && !user.active?
user
end
|