Skip to content

JWK Set

Nov Matake edited this page Aug 11, 2022 · 8 revisions

JSON Web Key Set (JWKs)

Encoding

JSON::JWK::Set can be initiated by putting an array of JSON::JWK instances, or Hash represented JSON Web Key Set.

JSON::JWK::Set.new(jwk1, jwk2, jwk3, ...)
JSON::JWK::Set.new([jwk1, jwk2, jwk3, ...])
JSON::JWK::Set.new(
  keys: [{
    kty: :RSA,
    e: 'AQAB',
    n: 'AK8ppaAGn6N3jDic2...'
  }, {
    :
  }]
)

Decoding

Just call JSON::JWK::Set#to_json.

Fetching

# NOTE: Optionally by setting cache instance, JWKs are cached by kid.
JSON::JWK::Set::Fetcher.cache = Rails.cache

JSON::JWK::Set::Fetcher.fetch(jwks_uri, kid: kid) # => returns JSON::JWK instance or raise JSON::JWK::Set::KidNotFound
JSON::JWK::Set::Fetcher.fetch(jwks_uri, kid: kid, auto_detect: false) # => => returns JSON::JWK::Set
Clone this wiki locally