You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Ruby SDK, WorkOS::UserManagement.load_sealed_session seems to fetch the remote JWKS on every load, adding about 100ms to each authenticated request.
We use Rails and for every authenticated request, we call authorize_request which does the following:
session = WorkOS::UserManagement.load_sealed_session
result = session.authenticate
@user = result[:user]
After implementing WorkOS, we realized all of our authenticated endpoints now take 100ms longer on the backend. It took some digging through our Sentry profiles to find that create_remote_jwk_set was called repeatedly:
I see the problem, I think we should able to move that to when you initialize the SDK instead of on every session load. Will look into fixing this soon.
I see the problem, I think we should able to move that to when you initialize the SDK instead of on every session load. Will look into fixing this soon.
thanks for looking into this! would appreciate if you can prioritize this for us.
We ran into this when we noticed the JWKS call was taking up 30-45% of our request processing time.
For now we've worked around it by adding the following to our initializer (config/initializers/workos.rb):
# We load and authenticate the sealed session each request.# Just loading the JWKS to verify the token was taking up 30% of our server request time!## Cache this for 5 minutes to stop having to do that on every request.# Ideally we'd cache longer and just update it if we triggered a validation errormoduleCacheJWKSetprivatedefcreate_remote_jwk_set(uri)Rails.cache.fetch("workos-jwk-set",expires_in: 5.minutes)dosuperendendendWorkOS::Session.prepend(CacheJWKSet)
In the Ruby SDK,
WorkOS::UserManagement.load_sealed_session
seems to fetch the remote JWKS on every load, adding about 100ms to each authenticated request.We use Rails and for every authenticated request, we call
authorize_request
which does the following:After implementing WorkOS, we realized all of our authenticated endpoints now take 100ms longer on the backend. It took some digging through our Sentry profiles to find that
create_remote_jwk_set
was called repeatedly:workos-ruby/lib/workos/session.rb
Line 26 in 8c401c2
We host our services on Render.com on GCP's
oregon-1
region.Please advise if there is a better way to authenticate the token or if improvements can be made to the SDK. Thanks!
The text was updated successfully, but these errors were encountered: