clerk / clerk-sdk-ruby

Access the Clerk Backend API from Ruby
MIT License
18 stars 8 forks source link

fix: Make JWKS cache shared between SDK instances #27

Closed agis closed 1 year ago

agis commented 1 year ago

After 1123911 the JWKs cache wasn't working as expected, since the middleware constructed a new SDK instance on each request. So each request was effectively bypassing the cache, since the cache was essentially an instance variable which was re-initialized anew every time.

With this change, the JWKs cache is made thread-safe and shared between all instances of the SDK.

Fixes AUTH-76

linear[bot] commented 1 year ago
AUTH-76 Ruby SDK middleware bypasses the JWKs cache

After [this change](https://github.com/clerkinc/clerk-sdk-ruby/commit/11239115d79603f5178bfdada9fe94369427818f#diff-c470f32f382c9027c74ffad70191532dc9b74554144ba45bcf5deffa6c2727d0L194-R194), the auth middleware essentially does not leverage the JWKS cache, since a new SDK instance is constructed per request (and the cache is essentially an instance variable). We have to find a way to leverage some form of JWKs caching while also keeping our middleware thread-safe. The above issue was discovered after we saw excessive amounts of requests to the BAPI JWKs endpoint from Finary.