Class: Rails::Vault::JWT::KeyProvider
- Inherits:
-
Object
- Object
- Rails::Vault::JWT::KeyProvider
- Defined in:
- lib/rails/vault/jwt/key_provider.rb
Instance Method Summary collapse
- #fetch_keys(issuer) ⇒ Object
-
#initialize(cache = nil) ⇒ KeyProvider
constructor
A new instance of KeyProvider.
- #keys(issuer) ⇒ Object
Constructor Details
#initialize(cache = nil) ⇒ KeyProvider
Returns a new instance of KeyProvider.
10 11 12 |
# File 'lib/rails/vault/jwt/key_provider.rb', line 10 def initialize(cache = nil) @cache = cache || Rails::Vault::JWT.config.cache end |
Instance Method Details
#fetch_keys(issuer) ⇒ Object
26 27 28 29 |
# File 'lib/rails/vault/jwt/key_provider.rb', line 26 def fetch_keys(issuer) raw = Net::HTTP.get URI.parse("#{issuer}/.well-known/keys") JSON.parse raw, symbolize_names: true end |
#keys(issuer) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rails/vault/jwt/key_provider.rb', line 14 def keys(issuer) raise InvalidIssuer if JWT.config.valid_issuers.any? && !(JWT.config.valid_issuers.include? issuer) if @cache.respond_to?(:fetch) @cache.fetch("keys/#{issuer}", expires_in: 5.minutes) do fetch_keys issuer end else fetch_keys issuer end end |