[PR #6171] [MERGED] Fix/test rotating keys #14744

Closed
opened 2026-04-13 09:36:59 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6171
Author: @Paola3stefania
Created: 11/21/2025
Status: Merged
Merged: 11/21/2025
Merged by: @Bekacru

Base: fix/jwksHead: fix/test-rotating-keys


📝 Commits (1)

  • b5738eb Instead of assuming position 0, the test now extracts the kid from the decoded JWT, verifies that kid exists in the JWKS (any position). This works regardless of order or rotation state, working with key rotation.

📊 Changes

1 file changed (+7 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/plugins/jwt/jwt.test.ts (+7 -1)

📄 Description

from feat(jwt): add key rotation PR key rotations


Summary by cubic

Add configurable JWT key rotation with rotationInterval and gracePeriod to keep tokens verifiable while rotating keys. JWKS now only returns keys that are still valid within the grace window, and signing auto-rotates when the latest key is expired.

  • New Features

    • Enable key rotation via rotationInterval (seconds) and gracePeriod (seconds; default 30 days).
    • Store expiresAt on keys; JWKS filters out keys beyond gracePeriod.
    • Auto-create a new key on sign when the latest key has expired.
  • Refactors

    • Removed adapter.getLatestKey override; latest key is derived from getJwks sorted by createdAt.
    • Updated docs and schema to include expiresAt and rotation options.
    • Added rotation tests; JWT test now checks the kid exists in JWKS without assuming order.

Written for commit b5738eb2a3. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6171 **Author:** [@Paola3stefania](https://github.com/Paola3stefania) **Created:** 11/21/2025 **Status:** ✅ Merged **Merged:** 11/21/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `fix/jwks` ← **Head:** `fix/test-rotating-keys` --- ### 📝 Commits (1) - [`b5738eb`](https://github.com/better-auth/better-auth/commit/b5738eb2a361a9d56ed2b902e17ed258e99a5682) Instead of assuming position 0, the test now extracts the kid from the decoded JWT, verifies that kid exists in the JWKS (any position). This works regardless of order or rotation state, working with key rotation. ### 📊 Changes **1 file changed** (+7 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/jwt/jwt.test.ts` (+7 -1) </details> ### 📄 Description from feat(jwt): add key rotation PR [key rotations](https://github.com/better-auth/better-auth/pull/6147) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add configurable JWT key rotation with rotationInterval and gracePeriod to keep tokens verifiable while rotating keys. JWKS now only returns keys that are still valid within the grace window, and signing auto-rotates when the latest key is expired. - **New Features** - Enable key rotation via rotationInterval (seconds) and gracePeriod (seconds; default 30 days). - Store expiresAt on keys; JWKS filters out keys beyond gracePeriod. - Auto-create a new key on sign when the latest key has expired. - **Refactors** - Removed adapter.getLatestKey override; latest key is derived from getJwks sorted by createdAt. - Updated docs and schema to include expiresAt and rotation options. - Added rotation tests; JWT test now checks the kid exists in JWKS without assuming order. <sup>Written for commit b5738eb2a361a9d56ed2b902e17ed258e99a5682. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 09:36:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#14744