2022-01-24 23:50:12 +01:00
|
|
|
class ApiKey < ApplicationRecord
|
|
|
|
encrypts :token, deterministic: true
|
|
|
|
|
|
|
|
belongs_to :bearer, polymorphic: true
|
|
|
|
|
|
|
|
def self.authenticate_by_token!(token)
|
|
|
|
find_by! token: token
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.authenticate_by_token(token)
|
|
|
|
authenticate_by_token! token
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
nil
|
|
|
|
end
|
2023-02-26 15:09:08 +01:00
|
|
|
end
|