[PR #4041] [MERGED] feat(jwt): sign with jwt for custom claims #13399

Closed
opened 2026-04-13 08:54:39 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4041
Author: @Bekacru
Created: 8/16/2025
Status: Merged
Merged: 8/16/2025
Merged by: @Bekacru

Base: canaryHead: feat/sign-jwt


📝 Commits (1)

  • 13d2920 feat(jwt): sign with jwt for artbitrary payload

📊 Changes

3 files changed (+124 additions, -23 deletions)

View changed files

📝 packages/better-auth/src/plugins/jwt/index.ts (+32 -2)
📝 packages/better-auth/src/plugins/jwt/jwt.test.ts (+57 -0)
📝 packages/better-auth/src/plugins/jwt/sign.ts (+35 -21)

📄 Description

Summary by cubic

Adds a server-only API to sign JWTs with any payload and refactors JWT signing for reuse. This enables services to mint non-session tokens with custom claims.

  • New Features

    • POST /sign-jwt: accepts { payload, overrideOptions } and returns { token }.
    • Validates body with zod; payload is a JWTPayload.
    • Uses latest JWK (EdDSA by default) with kid in header; issuer/audience default to baseURL; expiration defaults to 15m.
    • Allows per-request override of JwtOptions.
  • Refactors

    • Extracted signJWT(ctx, { payload, options }) and updated getJwtToken to call it.
    • Ensures sub is set from session or getSubject for session-issued tokens.
    • Added tests to confirm token creation and verification against JWKS.

🔄 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/4041 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 8/16/2025 **Status:** ✅ Merged **Merged:** 8/16/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/sign-jwt` --- ### 📝 Commits (1) - [`13d2920`](https://github.com/better-auth/better-auth/commit/13d29208cf7761dc80a4d67cab07734c94281dd8) feat(jwt): sign with jwt for artbitrary payload ### 📊 Changes **3 files changed** (+124 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/jwt/index.ts` (+32 -2) 📝 `packages/better-auth/src/plugins/jwt/jwt.test.ts` (+57 -0) 📝 `packages/better-auth/src/plugins/jwt/sign.ts` (+35 -21) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds a server-only API to sign JWTs with any payload and refactors JWT signing for reuse. This enables services to mint non-session tokens with custom claims. - New Features - POST /sign-jwt: accepts { payload, overrideOptions } and returns { token }. - Validates body with zod; payload is a JWTPayload. - Uses latest JWK (EdDSA by default) with kid in header; issuer/audience default to baseURL; expiration defaults to 15m. - Allows per-request override of JwtOptions. - Refactors - Extracted signJWT(ctx, { payload, options }) and updated getJwtToken to call it. - Ensures sub is set from session or getSubject for session-issued tokens. - Added tests to confirm token creation and verification against JWKS. <!-- 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 08:54:39 -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#13399