2022-03-01 10:48:58 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-11-30 09:39:41 -05:00
|
|
|
module Api::AccessTokenTrackingConcern
|
2022-03-01 10:48:58 -05:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
ACCESS_TOKEN_UPDATE_FREQUENCY = 24.hours.freeze
|
|
|
|
|
|
|
|
included do
|
|
|
|
before_action :update_access_token_last_used
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_access_token_last_used
|
|
|
|
doorkeeper_token.update_last_used(request) if access_token_needs_update?
|
|
|
|
end
|
|
|
|
|
|
|
|
def access_token_needs_update?
|
|
|
|
doorkeeper_token.present? && (doorkeeper_token.last_used_at.nil? || doorkeeper_token.last_used_at < ACCESS_TOKEN_UPDATE_FREQUENCY.ago)
|
|
|
|
end
|
|
|
|
end
|