Module: OpenIDConnect::RequestObject::Claimable

Included in:
IdToken, UserInfo
Defined in:
lib/openid_connect/request_object/claimable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
# File 'lib/openid_connect/request_object/claimable.rb', line 4

def self.included(klass)
  klass.send :attr_optional, :claims
end

Instance Method Details

#accessible?(claim) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/openid_connect/request_object/claimable.rb', line 49

def accessible?(claim)
  claims.try(:include?, claim)
end

#as_json(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/openid_connect/request_object/claimable.rb', line 30

def as_json(options = {})
  keys = claims.try(:keys)
  hash = super
  Array(keys).each do |key|
    hash[:claims][key] ||= nil
  end
  hash
end

#initialize(attributes = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/openid_connect/request_object/claimable.rb', line 8

def initialize(attributes = {})
  super
  if claims.present?
    _claims_ = {}
    claims.each do |key, value|
      _claims_[key] = case value
      when :optional, :voluntary
        {
          essential: false
        }
      when :required, :essential
        {
          essential: true
        }
      else
        value
      end
    end
    self.claims = _claims_.with_indifferent_access
  end
end

#optional?(claim) ⇒ Boolean Also known as: voluntary?

Returns:

  • (Boolean)


44
45
46
# File 'lib/openid_connect/request_object/claimable.rb', line 44

def optional?(claim)
  accessible?(claim) && !required?(claim)
end

#required?(claim) ⇒ Boolean Also known as: essential?

Returns:

  • (Boolean)


39
40
41
# File 'lib/openid_connect/request_object/claimable.rb', line 39

def required?(claim)
  accessible?(claim) && claims[claim].is_a?(Hash) && claims[claim][:essential]
end