Class: WardenOpenidAuth::JWKS

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

Overview

Represents a JSON Web Key Set. It will cache the results of the web request to get the JWKS so that it does not need to make an external request for the JWKS to authenticate every user.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jwks_url:, config: WardenOpenidAuth.config) ⇒ JWKS

Returns a new instance of JWKS.

Parameters:

  • jwks_url (String)

    the URL that the JSON Web Key Set can be retrieved from.

  • config (#cache, #cache_options) (defaults to: WardenOpenidAuth.config)

    the object that holds the cache and cache options.



13
14
15
16
17
# File 'lib/warden_openid_auth/jwks.rb', line 13

def initialize(jwks_url:, config: WardenOpenidAuth.config)
  @jwks_url = jwks_url
  @cache = config.cache
  @cache_options = config.cache_options
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



9
10
11
# File 'lib/warden_openid_auth/jwks.rb', line 9

def cache
  @cache
end

#cache_optionsObject (readonly)

Returns the value of attribute cache_options.



9
10
11
# File 'lib/warden_openid_auth/jwks.rb', line 9

def cache_options
  @cache_options
end

#jwks_urlObject (readonly)

Returns the value of attribute jwks_url.



9
10
11
# File 'lib/warden_openid_auth/jwks.rb', line 9

def jwks_url
  @jwks_url
end

Instance Method Details

#key_setHash

Checks the cache to see if it contains the JSON Web Key Set and returns it. If it is not in the cache it will fetch it from the URL specified.

Returns:

  • (Hash)

    a Hash representation of the JSON Web Key Set.



23
24
25
26
27
28
# File 'lib/warden_openid_auth/jwks.rb', line 23

def key_set
  result = cache.read(cache_key)
  return result unless result.nil?

  fetch_and_store_jwks
end