class KeycloakRack::KeyResolver
A caching resolver that wraps around {KeycloakRack::KeyFetcher} to cache its result for {KeycloakRack::Config#cache_ttl} seconds (default: 1.day)
@api private
Attributes
cached_public_key_retrieved_at[R]
@!attribute [r] cached_public_key_retrieved_at
@return [ActiveSupport::TimeWithZone]
cached_public_keys[R]
@!attribute [r] cached_public_keys
@return [Dry::Monads::Success({ Symbol => <{ Symbol => String }> })] @return [Dry::Monads::Failure]
Public Class Methods
new(**)
click to toggle source
Calls superclass method
# File lib/keycloak_rack/key_resolver.rb, line 22 def initialize(**) super @cached_public_keys = Dry::Monads.Failure("nothing fetched yet") @cached_public_key_retrieved_at = 1.year.ago end
Public Instance Methods
find_public_keys()
click to toggle source
@see KeycloakRack::PublicKeyResolver#find_public_keys @return [Dry::Monads::Success({ Symbol => Object })] @return [Dry::Monads::Failure(Symbol, String)]
# File lib/keycloak_rack/key_resolver.rb, line 32 def find_public_keys fetch! if should_refetch? @cached_public_keys end
has_failed_fetch?()
click to toggle source
# File lib/keycloak_rack/key_resolver.rb, line 38 def has_failed_fetch? @cached_public_keys.failure? end
has_outdated_cache?()
click to toggle source
# File lib/keycloak_rack/key_resolver.rb, line 42 def has_outdated_cache? Time.current > @cached_public_key_expires_at end
refresh!()
click to toggle source
@return [void]
# File lib/keycloak_rack/key_resolver.rb, line 47 def refresh! fetch! end
should_refetch?()
click to toggle source
# File lib/keycloak_rack/key_resolver.rb, line 51 def should_refetch? has_failed_fetch? || has_outdated_cache? end
Private Instance Methods
fetch!()
click to toggle source
@return [void]
# File lib/keycloak_rack/key_resolver.rb, line 58 def fetch! @cached_public_keys = fetcher.find_public_keys @cached_public_key_retrieved_at = Time.current @cached_public_key_expires_at = @cached_public_key_retrieved_at + cache_ttl.seconds end