Class: TrueLayerSigning::JwsHeader
- Inherits:
-
Object
- Object
- TrueLayerSigning::JwsHeader
- Defined in:
- lib/truelayer-signing/utils.rb
Instance Attribute Summary collapse
-
#alg ⇒ Object
readonly
Returns the value of attribute alg.
-
#jku ⇒ Object
readonly
Returns the value of attribute jku.
-
#kid ⇒ Object
readonly
Returns the value of attribute kid.
-
#tl_headers ⇒ Object
readonly
Returns the value of attribute tl_headers.
-
#tl_version ⇒ Object
readonly
Returns the value of attribute tl_version.
Instance Method Summary collapse
- #filter_headers(headers) ⇒ Object
-
#initialize(args = {}) ⇒ JwsHeader
constructor
A new instance of JwsHeader.
- #to_h ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ JwsHeader
Returns a new instance of JwsHeader.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/truelayer-signing/utils.rb', line 5 def initialize(args = {}) raise(Error, "TRUELAYER_SIGNING_CERTIFICATE_ID is missing") \ if TrueLayerSigning.certificate_id.nil? || TrueLayerSigning.certificate_id.empty? @alg = args[:alg] || TrueLayerSigning.algorithm @kid = args[:kid] || TrueLayerSigning.certificate_id @tl_version = TrueLayerSigning.version @tl_headers = retrieve_headers(args[:tl_headers]) @jku = args[:jku] || nil end |
Instance Attribute Details
#alg ⇒ Object (readonly)
Returns the value of attribute alg.
3 4 5 |
# File 'lib/truelayer-signing/utils.rb', line 3 def alg @alg end |
#jku ⇒ Object (readonly)
Returns the value of attribute jku.
3 4 5 |
# File 'lib/truelayer-signing/utils.rb', line 3 def jku @jku end |
#kid ⇒ Object (readonly)
Returns the value of attribute kid.
3 4 5 |
# File 'lib/truelayer-signing/utils.rb', line 3 def kid @kid end |
#tl_headers ⇒ Object (readonly)
Returns the value of attribute tl_headers.
3 4 5 |
# File 'lib/truelayer-signing/utils.rb', line 3 def tl_headers @tl_headers end |
#tl_version ⇒ Object (readonly)
Returns the value of attribute tl_version.
3 4 5 |
# File 'lib/truelayer-signing/utils.rb', line 3 def tl_version @tl_version end |
Instance Method Details
#filter_headers(headers) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/truelayer-signing/utils.rb', line 23 def filter_headers(headers) required_header_keys = tl_headers.split(",").reject { |key| key.empty? } normalised_headers = {} headers.to_a.each { |header| normalised_headers[header.first.downcase] = header.last } ordered_headers = required_header_keys.map do |key| value = normalised_headers[key.downcase] raise(Error, "Missing header declared in signature: #{key.downcase}") unless value [key, value] end ordered_headers.to_h end |
#to_h ⇒ Object
17 18 19 20 21 |
# File 'lib/truelayer-signing/utils.rb', line 17 def to_h hash = instance_variables.map { |var| [var[1..-1].to_sym, instance_variable_get(var)] }.to_h hash.reject { |key, _value| hash[key].nil? } end |