access_token_tracking_concern.rb 532 B

123456789101112131415161718192021
  1. # frozen_string_literal: true
  2. module AccessTokenTrackingConcern
  3. extend ActiveSupport::Concern
  4. ACCESS_TOKEN_UPDATE_FREQUENCY = 24.hours.freeze
  5. included do
  6. before_action :update_access_token_last_used
  7. end
  8. private
  9. def update_access_token_last_used
  10. doorkeeper_token.update_last_used(request) if access_token_needs_update?
  11. end
  12. def access_token_needs_update?
  13. doorkeeper_token.present? && (doorkeeper_token.last_used_at.nil? || doorkeeper_token.last_used_at < ACCESS_TOKEN_UPDATE_FREQUENCY.ago)
  14. end
  15. end