Skip to content

Commit

Permalink
feat: install ActiveSupport for jwks caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa Burroughs committed Dec 5, 2024
1 parent 06b6907 commit cf9d32a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source 'https://rubygems.org'
gemspec

group :development do
gem 'activesupport', '~> 8.0'
gem 'dotenv', '~> 3.1'
gem 'prettier_print', '~> 1.2'
gem 'rack', '~> 3.1'
Expand Down
9 changes: 5 additions & 4 deletions lib/passageidentity/auth.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'active_support'
require 'openssl'
require 'base64'
require 'jwt'
Expand All @@ -14,7 +15,7 @@ class Auth

# rubocop:disable Metrics/AbcSize
def initialize(app_id, api_key, auth_strategy)
@app_cache = {}
@app_cache = ActiveSupport::Cache::MemoryStore.new
@app_id = app_id
@api_key = api_key
@auth_strategy = auth_strategy
Expand Down Expand Up @@ -197,7 +198,7 @@ def fetch_jwks
auth_gw_connection.get("/v1/apps/#{@app_id}/.well-known/jwks.json")
@jwks = response.body

!cache(@app_id) && cache(key: @app_id, jwks: @jwks)
cache(key: @app_id, jwks: @jwks)
end
end

Expand All @@ -220,11 +221,11 @@ def user_exists?(user_id)
end

def cache(key)
@app_cache[key]
@app_cache.read(key)
end

def cache=(key:, jwks:)
@app_cache[key] = jwks
@app_cache.write(key, jwks)
end

def jwk_exists(token)
Expand Down

0 comments on commit cf9d32a

Please sign in to comment.