Class: StandardId::Provider::ConsentGrant

Inherits:
ApplicationRecord show all
Defined in:
app/models/standard_id/provider/consent_grant.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.grant!(account:, client_application:, scopes:) ⇒ Object



16
17
18
19
20
21
22
23
# File 'app/models/standard_id/provider/consent_grant.rb', line 16

def self.grant!(account:, client_application:, scopes:)
  transaction do
    active.where(account: , client_application: client_application).each(&:revoke!)
    create!(account: , client_application: client_application, scopes: scopes)
  end
rescue ActiveRecord::RecordNotUnique
  retry
end

Instance Method Details

#covers_scopes?(requested_scopes) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'app/models/standard_id/provider/consent_grant.rb', line 29

def covers_scopes?(requested_scopes)
  granted = scopes.to_s.split(/\s+/)
  (requested_scopes - granted).empty?
end

#revoke!Object



25
26
27
# File 'app/models/standard_id/provider/consent_grant.rb', line 25

def revoke!
  update!(revoked_at: Time.current)
end