Skip to content

Cache Remote JWKS Fetch #334

@danielduan

Description

@danielduan

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:

@jwks = create_remote_jwk_set(URI(@user_management.get_jwks_url(client_id)))

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!

Screenshot 2024-11-18 at 5 12 29 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions