Class: OpenIDConnect::Discovery::Provider::Config::Response

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, AttrOptional, AttrRequired
Defined in:
lib/openid_connect/discovery/provider/config/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Response



60
61
62
63
64
65
# File 'lib/openid_connect/discovery/provider/config/response.rb', line 60

def initialize(hash)
  (required_attributes + optional_attributes).each do |key|
    self.send "#{key}=", hash[key]
  end
  @raw = hash
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



9
10
11
# File 'lib/openid_connect/discovery/provider/config/response.rb', line 9

def raw
  @raw
end

Instance Method Details

#as_json(options = {}) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/openid_connect/discovery/provider/config/response.rb', line 67

def as_json(options = {})
  validate!
  (required_attributes + optional_attributes).inject({}) do |hash, _attr_|
    value = self.send _attr_
    hash.merge! _attr_ => value unless value.nil?
    hash
  end
end

#jwksObject



80
81
82
83
84
85
# File 'lib/openid_connect/discovery/provider/config/response.rb', line 80

def jwks
  @jwks ||= JSON.parse(
    OpenIDConnect.http_client.get_content(jwks_uri)
  ).with_indifferent_access
  JSON::JWK::Set.new @jwks[:keys]
end

#public_keysObject



87
88
89
90
91
# File 'lib/openid_connect/discovery/provider/config/response.rb', line 87

def public_keys
  @public_keys ||= jwks.collect do |jwk|
    JSON::JWK.decode jwk
  end
end

#validate!Object



76
77
78
# File 'lib/openid_connect/discovery/provider/config/response.rb', line 76

def validate!
  valid? or raise ValidationFailed.new(self)
end