diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a6f780..93e3cec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.0.0-rc.10] - 2022-05-26 +### Changed +- Improved caching of requests to Auth0. + ## [1.0.0-rc.9] - 2022-05-25 ### Fixed - Loading user's permissions above 100 limit. diff --git a/Gemfile.lock b/Gemfile.lock index 935d608..d6a991b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,11 +87,12 @@ GIT PATH remote: . specs: - devise-auth0 (1.0.0.rc9) + devise-auth0 (1.0.0.rc10) auth0 (~> 5.6) devise (~> 4.8) dry-configurable (~> 0.13) faraday (~> 1.10.0) + faraday-http-cache jwt (~> 2.3) mail net-smtp @@ -157,6 +158,8 @@ GEM faraday-em_http (1.0.0) faraday-em_synchrony (1.0.0) faraday-excon (1.1.0) + faraday-http-cache (2.3.0) + faraday (>= 0.8) faraday-httpclient (1.0.1) faraday-multipart (1.0.3) multipart-post (>= 1.2, < 3) @@ -170,7 +173,7 @@ GEM hashdiff (1.0.1) hashie (5.0.0) http-accept (1.7.0) - http-cookie (1.0.4) + http-cookie (1.0.5) domain_name (~> 0.5) i18n (1.10.0) concurrent-ruby (~> 1.0) @@ -321,12 +324,12 @@ GEM sqlite3 (1.4.2) thor (1.2.1) timecop (0.9.5) - timeout (0.2.0) + timeout (0.3.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) unf (0.1.4) unf_ext - unf_ext (0.0.8.1) + unf_ext (0.0.8.2) unicode-display_width (2.1.0) vcr (6.1.0) warden (1.2.9) diff --git a/devise-auth0.gemspec b/devise-auth0.gemspec index 23408df..2a2ca09 100644 --- a/devise-auth0.gemspec +++ b/devise-auth0.gemspec @@ -29,6 +29,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency("devise", "~> 4.8") s.add_runtime_dependency("dry-configurable", "~> 0.13") s.add_runtime_dependency("faraday", "~> 1.10.0") + s.add_runtime_dependency("faraday-http-cache") s.add_runtime_dependency("jwt", "~> 2.3") s.add_runtime_dependency("mail") s.add_runtime_dependency("net-smtp") diff --git a/lib/devise/auth0/token.rb b/lib/devise/auth0/token.rb index 15d286a..0374d60 100644 --- a/lib/devise/auth0/token.rb +++ b/lib/devise/auth0/token.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "faraday" +require "faraday/http_cache" require "jwt" module Devise @@ -40,7 +41,9 @@ def user "email" => "#{uid}@#{config.domain}", } else - client.user(auth0_id) + ::Devise.auth0.cache.fetch("devise-auth0/#{auth0_id}", expires_in: ::Devise.auth0.cache_expires_in) do + client.user(auth0_id) + end end end @@ -96,6 +99,7 @@ def issuer def jwks_hash conn = ::Faraday.new("https://#{config.custom_domain}") do |f| + f.use(:http_cache, store: ::Devise.auth0.cache) f.request(:retry, max: 3) f.adapter(::Faraday.default_adapter) end diff --git a/lib/devise/auth0/version.rb b/lib/devise/auth0/version.rb index 172e720..e5602f7 100644 --- a/lib/devise/auth0/version.rb +++ b/lib/devise/auth0/version.rb @@ -10,7 +10,7 @@ module VERSION MAJOR = 1 MINOR = 0 TINY = 0 - PRE = "rc9" + PRE = "rc10" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/spec/devise/auth0/model_spec.rb b/spec/devise/auth0/model_spec.rb index f894651..649727b 100644 --- a/spec/devise/auth0/model_spec.rb +++ b/spec/devise/auth0/model_spec.rb @@ -9,8 +9,6 @@ let(:model) { auth0_user_model } let(:user) { auth0_user } - before { Devise.auth0.cache.clear } - describe ".required_fields" do it { expect(described_class.required_fields(model)).to(eq([])) } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8dc16c3..f7d8dc2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -83,6 +83,7 @@ config.before do WebMock.reset! WebMock.disable_net_connect! + Devise.auth0.cache.clear end config.include(Devise::Test::ControllerHelpers, type: :controller)