File: set.rb

package info (click to toggle)
ruby-json-jwt 1.6.2-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 292 kB
  • sloc: ruby: 2,120; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 626 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module JSON
  class JWK
    class Set < Array
      class KidNotFound < JWT::Exception; end

      def initialize(*jwks)
        jwks = if jwks.first.is_a?(Hash) && (keys = jwks.first.with_indifferent_access[:keys])
          keys
        else
          jwks
        end
        jwks = Array(jwks).flatten.collect do |jwk|
          JWK.new jwk
        end
        replace jwks
      end

      def content_type
        'application/jwk-set+json'
      end

      def as_json(options = {})
        # NOTE: Array.new wrapper is requied to avoid CircularReferenceError
        {keys: Array.new(self)}
      end
    end
  end
end