lib/json/jwt.rb in json-jwt-1.8.2 vs lib/json/jwt.rb in json-jwt-1.8.3

- old
+ new

@@ -76,36 +76,47 @@ else super end end + def pretty_generate + [ + JSON.pretty_generate(header), + JSON.pretty_generate(self) + ] + end + class << self - def decode_compact_serialized(jwt_string, key_or_secret) + def decode_compact_serialized(jwt_string, key_or_secret, algorithms = nil, encryption_methods = nil) case jwt_string.count('.') + 1 when JWS::NUM_OF_SEGMENTS - JWS.decode_compact_serialized jwt_string, key_or_secret + JWS.decode_compact_serialized jwt_string, key_or_secret, algorithms when JWE::NUM_OF_SEGMENTS - JWE.decode_compact_serialized jwt_string, key_or_secret + JWE.decode_compact_serialized jwt_string, key_or_secret, algorithms, encryption_methods else raise InvalidFormat.new("Invalid JWT Format. JWT should include #{JWS::NUM_OF_SEGMENTS} or #{JWE::NUM_OF_SEGMENTS} segments.") end end - def decode_json_serialized(input, key_or_secret) + def decode_json_serialized(input, key_or_secret, algorithms = nil, encryption_methods = nil) input = input.with_indifferent_access if (input[:signatures] || input[:signature]).present? - JWS.decode_json_serialized input, key_or_secret + JWS.decode_json_serialized input, key_or_secret, algorithms elsif input[:ciphertext].present? - JWE.decode_json_serialized input, key_or_secret + JWE.decode_json_serialized input, key_or_secret, algorithms, encryption_methods else raise InvalidFormat.new("Unexpected JOSE JSON Serialization Format.") end end + + def pretty_generate(jwt_string) + decode(jwt_string, :skip_verification).pretty_generate + end end end end require 'json/jws' require 'json/jwe' require 'json/jwk' require 'json/jwk/jwkizable' -require 'json/jwk/set' \ No newline at end of file +require 'json/jwk/set'