Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in-memory cache for jwks to the jwtVerify method #85

Merged
merged 6 commits into from
Sep 3, 2024

Conversation

marcomontalbano
Copy link
Member

@marcomontalbano marcomontalbano commented Aug 21, 2024

What I did

I added an in-memory cache for jwks to the jwtVerify method trying to reduce rate-limiting errors.

I also added the jwk option to the jwtVerify. This way you can cache the jwt on your own and send the key to method for verification.

const maybeDecoded = await jwtVerify(accessToken, {
  jwk: {
    kty: 'RSA',
    n: 'rhMhwqeLIU1HTubDdY2-_gIzo57tKyF6oKnV7FgAN5RpLKqRoHt3W6h0hHFZtfqjAFnM901P9v3zdAcZVbBA_TfNuXYEoTJsJRhW4_L0fcXGt2yLyuH3xO1keCJrz4sbfe-md45snzVDGUPeYnEWipy7ySfbJsU5S_KfypsIvkRtctgqw5Excs-qjoDCSkkbiQZzkyJEJQ4PSi0fyx6ZIAmYJ1zwucUdpaYstXwyRik6u48vS07ctEHTbZL4p4LYbxoGzapHd_zlqw6KJ_wjpEANMjTAr0SCfQ3hOm19so-6G3N3s51ZabPvn_cAjnhkFnvXAhX38JuiUiGJuwU6ZFW_793qnSLclfCY0eeUekrYt7Btl1zuPvVkOM_WL4HVlrLR1Q4P0_nuBUZEdMJjhsdX8r508GPZI2OT_AQvjpOCNo0Ug0KvL1Tm2-l6YGc2Fs7b0uP_o3qQ-IVQ50C0ZAZA5gEOtLhWFEj9SUIm9-P8KDpffYBvSSMtxLwdkRBsc05xac9x53B-TF_Jwitgpm01R-W5AQC-qd6cXCwEQRKrFNWutjfVwbU67Z1kX1M1tM2197xhmXgScOOnGJob3P9FfFYPjjfU2OPaLl8_yxvF4cxXn_XKx271Ln6LtIDI409k6kA0L-n4sosyj4kV8tfrydyHWdmj4po9ghVfyZs',
    e: 'AQAB',
    ext: true,
    kid: '367a4928f8988e8f120183c7',
    alg: 'RS512',
    use: 'sig'
  }
})

Copy link

vercel bot commented Aug 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
commercelayer-js-auth-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 30, 2024 9:49am

Copy link

netlify bot commented Aug 21, 2024

Deploy Preview for commercelayer-js-auth-nextjs canceled.

Name Link
🔨 Latest commit f7703ea
🔍 Latest deploy log https://app.netlify.com/sites/commercelayer-js-auth-nextjs/deploys/66d19590fc3747000861a3e6

@marcomontalbano marcomontalbano changed the title In memory cache verify Introduce an in-memory cache for jwks to the jwtVerify method Aug 21, 2024
@marcomontalbano marcomontalbano changed the title Introduce an in-memory cache for jwks to the jwtVerify method Add in-memory cache for jwks to the jwtVerify method Aug 21, 2024
@marcomontalbano marcomontalbano self-assigned this Aug 21, 2024
@marcomontalbano marcomontalbano added the enhancement New feature or request label Aug 21, 2024
@marcomontalbano marcomontalbano marked this pull request as ready for review August 22, 2024 05:47
@marcomontalbano marcomontalbano requested review from alessani and removed request for alessani August 26, 2024 15:45
malessani
malessani previously approved these changes Aug 26, 2024
@marcomontalbano marcomontalbano merged commit e71c163 into main Sep 3, 2024
6 checks passed
@marcomontalbano marcomontalbano deleted the in-memory-cache-verify branch September 3, 2024 08:15
@marcomontalbano marcomontalbano mentioned this pull request Sep 3, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants