[PR #9080] [CLOSED] feat(oauth-provider): customTokenResponseFields, Zod validation, createUserTokens refactor #16669

Closed
opened 2026-04-13 10:38:19 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/9080
Author: @gustavovalverde
Created: 4/9/2026
Status: Closed

Base: mainHead: feat/oauth-provider-at-hash-v2


📝 Commits (4)

  • b3f9af5 feat(oauth-provider): compute at_hash in id tokens per OIDC Core §3.1.3.6
  • 071071c chore: add changeset for at_hash feature
  • db7ee05 fix(oauth-provider): omit at_hash when custom signer alg is unknown
  • cfad76b refactor(oauth-provider): resolve signing key once, add runtime alg validation

📊 Changes

6 files changed (+387 additions, -45 deletions)

View changed files

.changeset/oauth-provider-at-hash.md (+10 -0)
📝 packages/better-auth/src/plugins/jwt/index.ts (+1 -1)
📝 packages/better-auth/src/plugins/jwt/sign.ts (+46 -22)
📝 packages/better-auth/src/plugins/jwt/types.ts (+13 -0)
📝 packages/oauth-provider/src/token.test.ts (+236 -3)
📝 packages/oauth-provider/src/token.ts (+81 -19)

📄 Description

Summary

Supersedes #8635 (auth_session passthrough for first-party app step-up).

Instead of hardcoding auth_session into the verification value and threading it through positional parameters, this PR builds the proper foundation:

  • Add customTokenResponseFields callback to OAuthOptions for injecting custom fields into token endpoint responses across all grant types. Standard OAuth fields cannot be overridden. Follows the same pattern as customAccessTokenClaims and customIdTokenClaims.
  • Refactor createUserTokens from 10 positional params to a typed CreateUserTokensParams options object. Make user optional to unify handleClientCredentialsGrant through the same code path (eliminating 75 lines of duplicated token response construction).
  • Replace raw JSON.parse + type cast in checkVerificationValue with Zod runtime validation. Invalid JSON and malformed verification values now consistently return invalid_verification errors instead of 500s.

🔄 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/9080 **Author:** [@gustavovalverde](https://github.com/gustavovalverde) **Created:** 4/9/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/oauth-provider-at-hash-v2` --- ### 📝 Commits (4) - [`b3f9af5`](https://github.com/better-auth/better-auth/commit/b3f9af50e84d18da7f7b9f1eb79edfbab7998147) feat(oauth-provider): compute at_hash in id tokens per OIDC Core §3.1.3.6 - [`071071c`](https://github.com/better-auth/better-auth/commit/071071c6c34c131f9d5eab7760dad39b872410a0) chore: add changeset for at_hash feature - [`db7ee05`](https://github.com/better-auth/better-auth/commit/db7ee05952363d948c143d7325f7ec271f383f3e) fix(oauth-provider): omit at_hash when custom signer alg is unknown - [`cfad76b`](https://github.com/better-auth/better-auth/commit/cfad76ba6405d85161eb9258f187b71fa2cf19a3) refactor(oauth-provider): resolve signing key once, add runtime alg validation ### 📊 Changes **6 files changed** (+387 additions, -45 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/oauth-provider-at-hash.md` (+10 -0) 📝 `packages/better-auth/src/plugins/jwt/index.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/jwt/sign.ts` (+46 -22) 📝 `packages/better-auth/src/plugins/jwt/types.ts` (+13 -0) 📝 `packages/oauth-provider/src/token.test.ts` (+236 -3) 📝 `packages/oauth-provider/src/token.ts` (+81 -19) </details> ### 📄 Description ## Summary Supersedes #8635 (auth_session passthrough for first-party app step-up). Instead of hardcoding `auth_session` into the verification value and threading it through positional parameters, this PR builds the proper foundation: - Add `customTokenResponseFields` callback to `OAuthOptions` for injecting custom fields into token endpoint responses across all grant types. Standard OAuth fields cannot be overridden. Follows the same pattern as `customAccessTokenClaims` and `customIdTokenClaims`. - Refactor `createUserTokens` from 10 positional params to a typed `CreateUserTokensParams` options object. Make `user` optional to unify `handleClientCredentialsGrant` through the same code path (eliminating 75 lines of duplicated token response construction). - Replace raw `JSON.parse` + type cast in `checkVerificationValue` with Zod runtime validation. Invalid JSON and malformed verification values now consistently return `invalid_verification` errors instead of 500s. --- <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 10:38:19 -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#16669