[PR #7147] [CLOSED] fix(oauth-provider): metadata field handling in client registration #32703

Closed
opened 2026-04-17 23:27:23 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7147
Author: @bauerj
Created: 1/6/2026
Status: ❌ Closed

Base: main ← Head: fix/oauth-provider-metadata-handling


📝 Commits (8)

📊 Changes

5 files changed (+200 additions, -118 deletions)

View changed files

📝 packages/oauth-provider/src/oauthClient/endpoints.test.ts (+1 -0)
📝 packages/oauth-provider/src/oauthClient/index.ts (+111 -113)
📝 packages/oauth-provider/src/register.test.ts (+14 -0)
📝 packages/oauth-provider/src/register.ts (+8 -4)
📝 packages/oauth-provider/src/types/oauth.ts (+66 -1)

📄 Description

The metadata field in adminCreateOAuthClient was causing a SyntaxError: "[object Object]" is not valid JSON error when creating OAuth clients. This occurred because:

  1. The metadata field was not explicitly destructured in oauthToSchema, causing it to be included in the ...rest spread
  2. This resulted in double-wrapping: {"metadata": {"foo": "bar"}} instead of {"foo": "bar"}. This would result in storing JSON objects like { "metadata": ... } in the metadata column and returning double-nested metadata when querying.
  3. Database adapters auto-parse JSON columns, returning objects instead of strings
  4. schemaToOAuth attempted to JSON.parse() an already-parsed object, causing the error

This change enables setting the metadata field and returns data in a more useful format.

Closes: #7135


Summary by cubic

Fix metadata handling in OAuth client registration to stop double-wrapped data. Metadata is now stored and returned as a single nested object under the metadata field, and redirect_uris now defaults to an empty array.

  • Bug Fixes
    • Explicitly destructure metadata in oauthToSchema to avoid double-wrapping.
    • Return metadata as a dedicated field in schemaToOAuth.
    • Default redirect_uris to [] to prevent missing field errors.
    • Type jwks as JSONWebKeySet and allow client_secret_expires_at as string or number (default 0 in create).

Written for commit 93b4681af4. Summary will update 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/7147 **Author:** [@bauerj](https://github.com/bauerj) **Created:** 1/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/oauth-provider-metadata-handling` --- ### 📝 Commits (8) - [`abb83b3`](https://github.com/better-auth/better-auth/commit/abb83b3e4ce39347b2806c1d8f4b306479775f18) fix(oauth-provider): fix metadata field handling in client registration - [`4198a14`](https://github.com/better-auth/better-auth/commit/4198a1408efa5798c1c47801530ad8b0e79b18ab) fix: type - [`381a195`](https://github.com/better-auth/better-auth/commit/381a1951677014c15fef3f534b67435cca3b76e8) Merge branch 'canary' into fix/oauth-provider-metadata-handling - [`106d7fb`](https://github.com/better-auth/better-auth/commit/106d7fbdc79bc358f3a3b95a3b571e95f910eb2e) fix: type - [`4c4610d`](https://github.com/better-auth/better-auth/commit/4c4610d0f485eb94f544218ca58a0685f952afc5) fix: type - [`1ef6363`](https://github.com/better-auth/better-auth/commit/1ef636308298a5c1ad049bda771c75bc7f6e42c0) fix: unknown - [`d57872b`](https://github.com/better-auth/better-auth/commit/d57872b588d756cc09d03977bbb11fdd66e32501) fix: check string - [`93b4681`](https://github.com/better-auth/better-auth/commit/93b4681af4b89f1f766c12a8bcaa1d927b3132e7) fix: type ### 📊 Changes **5 files changed** (+200 additions, -118 deletions) <details> <summary>View changed files</summary> 📝 `packages/oauth-provider/src/oauthClient/endpoints.test.ts` (+1 -0) 📝 `packages/oauth-provider/src/oauthClient/index.ts` (+111 -113) 📝 `packages/oauth-provider/src/register.test.ts` (+14 -0) 📝 `packages/oauth-provider/src/register.ts` (+8 -4) 📝 `packages/oauth-provider/src/types/oauth.ts` (+66 -1) </details> ### 📄 Description The `metadata` field in `adminCreateOAuthClient` was causing a `SyntaxError: "[object Object]" is not valid JSON` error when creating OAuth clients. This occurred because: 1. The `metadata` field was not explicitly destructured in `oauthToSchema`, causing it to be included in the `...rest` spread 2. This resulted in double-wrapping: `{"metadata": {"foo": "bar"}}` instead of `{"foo": "bar"}`. This would result in storing JSON objects like { "metadata": ... } in the metadata column and returning double-nested metadata when querying. 3. Database adapters auto-parse JSON columns, returning objects instead of strings 4. `schemaToOAuth` attempted to `JSON.parse()` an already-parsed object, causing the error This change enables setting the metadata field and returns data in a more useful format. Closes: #7135 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fix metadata handling in OAuth client registration to stop double-wrapped data. Metadata is now stored and returned as a single nested object under the metadata field, and redirect_uris now defaults to an empty array. - **Bug Fixes** - Explicitly destructure metadata in oauthToSchema to avoid double-wrapping. - Return metadata as a dedicated field in schemaToOAuth. - Default redirect_uris to [] to prevent missing field errors. - Type jwks as JSONWebKeySet and allow client_secret_expires_at as string or number (default 0 in create). <sup>Written for commit 93b4681af4b89f1f766c12a8bcaa1d927b3132e7. Summary will update 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-17 23:27:23 -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#32703