First crack
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled

This commit is contained in:
Dan Milne
2025-10-23 16:45:00 +11:00
parent 1ff0a95392
commit 56f7dd7b3c
54 changed files with 1249 additions and 30 deletions

View File

@@ -0,0 +1,34 @@
class OidcAccessToken < ApplicationRecord
belongs_to :application
belongs_to :user
before_validation :generate_token, on: :create
before_validation :set_expiry, on: :create
validates :token, presence: true, uniqueness: true
scope :valid, -> { where("expires_at > ?", Time.current) }
scope :expired, -> { where("expires_at <= ?", Time.current) }
def expired?
expires_at <= Time.current
end
def active?
!expired?
end
def revoke!
update!(expires_at: Time.current)
end
private
def generate_token
self.token ||= SecureRandom.urlsafe_base64(48)
end
def set_expiry
self.expires_at ||= 1.hour.from_now
end
end