Class: KeycloakRack::KeyResolver Private

Inherits:
Object
  • Object
show all
Defined in:
lib/keycloak_rack/key_resolver.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A caching resolver that wraps around KeyFetcher to cache its result for Config#cache_ttl seconds (default: 1.day)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKeyResolver

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of KeyResolver.



22
23
24
25
26
27
# 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

Instance Attribute Details

#cached_public_key_retrieved_atActiveSupport::TimeWithZone (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (ActiveSupport::TimeWithZone)


15
16
17
# File 'lib/keycloak_rack/key_resolver.rb', line 15

def cached_public_key_retrieved_at
  @cached_public_key_retrieved_at
end

#cached_public_keysDry::Monads::Success({ Symbol => <{ Symbol => String }> }), Dry::Monads::Failure (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Dry::Monads::Success({ Symbol => <{ Symbol => String }> }))
  • (Dry::Monads::Failure)


20
21
22
# File 'lib/keycloak_rack/key_resolver.rb', line 20

def cached_public_keys
  @cached_public_keys
end

Instance Method Details

#find_public_keysDry::Monads::Success({ Symbol => Object }), Dry::Monads::Failure(Symbol, String)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Dry::Monads::Success({ Symbol => Object }))
  • (Dry::Monads::Failure(Symbol, String))

See Also:

  • PublicKeyResolver#find_public_keys


32
33
34
35
36
# File 'lib/keycloak_rack/key_resolver.rb', line 32

def find_public_keys
  fetch! if should_refetch?

  @cached_public_keys
end

#has_failed_fetch?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


38
39
40
# File 'lib/keycloak_rack/key_resolver.rb', line 38

def has_failed_fetch?
  @cached_public_keys.failure?
end

#has_outdated_cache?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


42
43
44
# File 'lib/keycloak_rack/key_resolver.rb', line 42

def has_outdated_cache?
  Time.current > @cached_public_key_expires_at
end

#refresh!void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



47
48
49
# File 'lib/keycloak_rack/key_resolver.rb', line 47

def refresh!
  fetch!
end

#should_refetch?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


51
52
53
# File 'lib/keycloak_rack/key_resolver.rb', line 51

def should_refetch?
  has_failed_fetch? || has_outdated_cache?
end