Module: SignIn::PublicJwks

Included in:
Idme::Service, Logingov::Service
Defined in:
lib/sign_in/public_jwks.rb

Instance Method Summary collapse

Instance Method Details

#jwks_loader(**options) ⇒ Object (private)



7
8
9
10
11
12
13
14
15
# File 'lib/sign_in/public_jwks.rb', line 7

def jwks_loader(**options)
  if options[:kid_not_found]
    Rails.logger.info("#{config.log_prefix} JWK not found, reloading public JWKs")
    Rails.cache.delete_matched(config.jwks_cache_key)
    @public_jwks = nil
  end

  public_jwks
end

#parse_public_jwks(response:) ⇒ Object (private)



28
29
30
31
32
# File 'lib/sign_in/public_jwks.rb', line 28

def parse_public_jwks(response:)
  jwks = JWT::JWK::Set.new(response.body)
  jwks.select! { |key| key[:use] == 'sig' }
  jwks
end

#public_jwksObject (private)



17
18
19
20
21
22
23
24
25
26
# File 'lib/sign_in/public_jwks.rb', line 17

def public_jwks
  @public_jwks ||= Rails.cache.fetch(config.jwks_cache_key, expires_in: config.jwks_cache_expiration) do
    response = perform(:get, config.public_jwks_path, nil, nil)
    Rails.logger.info("#{config.log_prefix} Get Public JWKs Success")

    parse_public_jwks(response:)
  end
rescue Common::Client::Errors::ClientError => e
  raise_client_error(e, 'Get Public JWKs')
end