Class: Inferno::DSL::JWKS

Inherits:
Object
  • Object
show all
Defined in:
lib/inferno/dsl/jwks.rb

Overview

The JWKS class provides methods to handle JSON Web Key Sets (JWKS) within Inferno.

This class allows users to fetch, parse, and manage JWKS, ensuring that the necessary keys for verifying tokens are available.

Class Method Summary collapse

Class Method Details

.jwks(user_jwks: nil) ⇒ JWT::JWK::Set

Parses and returns a JWT::JWK::Set object from the provided JWKS string or from the file located at the JWKS path. If a user-provided JWKS string is not available, it reads the JWKS from the file.

Examples:

# Using a user-provided JWKS string
user_jwks = '{"keys":[...]}'
jwks_set = Inferno::JWKS.jwks(user_jwks: user_jwks)

# Using the default JWKS file
jwks_set = Inferno::JWKS.jwks

Parameters:

  • user_jwks (String, nil) (defaults to: nil)

    An optional json containing the JWKS. If not provided, the method reads from the file.

Returns:

  • (JWT::JWK::Set)

    The parsed JWKS set.



71
72
73
# File 'lib/inferno/dsl/jwks.rb', line 71

def jwks(user_jwks: nil)
  JWT::JWK::Set.new(JSON.parse(user_jwks.presence || default_jwks_json))
end

.jwks_jsonString

Returns a formatted JSON string of the JWKS public keys that are used for verification. This method filters out keys that do not have the ‘verify’ operation.

Examples:

jwks_json = Inferno::JWKS.jwks_json
puts jwks_json

Returns:

  • (String)

    The formatted JSON string of the JWKS public keys.



18
19
20
21
22
23
# File 'lib/inferno/dsl/jwks.rb', line 18

def jwks_json
  @jwks_json ||=
    JSON.pretty_generate(
      { keys: jwks.export[:keys].select { |key| key[:key_ops]&.include?('verify') } }
    )
end