Class: Auth0::Mixins::Validation::Algorithm::RS256
- Inherits:
-
JWTAlgorithm
- Object
- JWTAlgorithm
- Auth0::Mixins::Validation::Algorithm::RS256
- Includes:
- HTTPProxy
- Defined in:
- lib/auth0/mixins/validation.rb
Overview
Represents the RS256 algorithm, which rely on public key certificates.
Constant Summary collapse
- @@cache =
Zache.new.freeze
Constants included from HTTPProxy
HTTPProxy::DEAFULT_RETRIES, HTTPProxy::MAX_ALLOWED_RETRIES, HTTPProxy::MAX_REQUEST_RETRY_DELAY, HTTPProxy::MAX_REQUEST_RETRY_JITTER, HTTPProxy::MIN_REQUEST_RETRY_DELAY
Instance Attribute Summary
Attributes included from HTTPProxy
#base_uri, #headers, #retry_count, #timeout
Class Method Summary collapse
-
.jwks_url(url, lifetime: 10 * 60) ⇒ RS256
Create a new instance passing the JWK set url.
-
.remove_jwks ⇒ Object
Clear the JWK set cache.
Instance Method Summary collapse
-
#fetched_jwks? ⇒ boolean
Returns whether or not the JWK set was fetched from the url.
-
#initialize(jwks_url, lifetime) ⇒ RS256
constructor
A new instance of RS256.
-
#jwks(force: false) ⇒ hash
Fetches the JWK set from the in-memory cache or from the url.
-
#name ⇒ string
Returns the algorithm name.
Methods included from HTTPProxy
#add_headers, #call, #encode_uri, #request, #request_with_retry, #retry_options, #safe_parse_json, #url
Constructor Details
#initialize(jwks_url, lifetime) ⇒ RS256
Returns a new instance of RS256.
293 294 295 296 297 298 299 300 |
# File 'lib/auth0/mixins/validation.rb', line 293 def initialize(jwks_url, lifetime) raise Auth0::InvalidParameter, 'Must supply a valid jwks_url' if jwks_url.to_s.empty? raise Auth0::InvalidParameter, 'Must supply a valid lifetime' unless lifetime.is_a?(Integer) && lifetime >= 0 @lifetime = lifetime @jwks_url = jwks_url @did_fetch_jwks = false end |
Class Method Details
.jwks_url(url, lifetime: 10 * 60) ⇒ RS256
Create a new instance passing the JWK set url.
283 284 285 |
# File 'lib/auth0/mixins/validation.rb', line 283 def jwks_url(url, lifetime: 10 * 60) new url, lifetime end |
.remove_jwks ⇒ Object
Clear the JWK set cache.
288 289 290 |
# File 'lib/auth0/mixins/validation.rb', line 288 def remove_jwks @@cache.remove_by { true } end |
Instance Method Details
#fetched_jwks? ⇒ boolean
Returns whether or not the JWK set was fetched from the url.
331 332 333 |
# File 'lib/auth0/mixins/validation.rb', line 331 def fetched_jwks? @did_fetch_jwks end |
#jwks(force: false) ⇒ hash
Fetches the JWK set from the in-memory cache or from the url.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/auth0/mixins/validation.rb', line 310 def jwks(force: false) result = fetch_jwks if force if result @@cache.put(@jwks_url, result, lifetime: @lifetime) return result end previous_value = @@cache.last(@jwks_url) @@cache.get(@jwks_url, lifetime: @lifetime, dirty: true) do new_value = fetch_jwks raise Auth0::InvalidIdToken, 'Could not fetch the JWK set' unless new_value || previous_value new_value || previous_value end end |
#name ⇒ string
Returns the algorithm name.
304 305 306 |
# File 'lib/auth0/mixins/validation.rb', line 304 def name 'RS256' end |