[PR #8633] [MERGED] fix(oauth-provider): let customIdTokenClaims override acr and auth_time #25006

Closed
opened 2026-04-15 22:41:16 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8633
Author: @gustavovalverde
Created: 3/16/2026
Status: Merged
Merged: 3/28/2026
Merged by: @gustavovalverde

Base: mainHead: fix/oauth-provider-acr-auth-time-override


📝 Commits (2)

  • 8615f09 fix(oauth-provider): let customIdTokenClaims override acr and auth_time
  • f78ffd6 test(oauth-provider): cover nonce and sid in pinned claims test

📊 Changes

2 files changed (+146 additions, -1 deletions)

View changed files

📝 packages/oauth-provider/src/token.test.ts (+145 -0)
📝 packages/oauth-provider/src/token.ts (+1 -1)

📄 Description

Problem

Follow-up to #7865, which fixed the ordering of userClaims vs customClaims so that customIdTokenClaims can override standard OIDC claims. That fix placed ...customClaims after ...userClaims, but auth_time and acr are assigned after the customClaims spread, silently overwriting any custom values.

This matters for providers that compute acr dynamically (e.g., from MFA status or step-up authentication level) and need customIdTokenClaims to be the final authority.

Changes

In createIdToken, move auth_time and acr assignments before the ...customClaims spread. The resulting order is: userClaimsauth_time/acr (defaults) → customClaims (overrides) → iss/sub/aud/iat/exp (non-overridable).

One-line change.

References


Summary by cubic

Fixes ID token claim precedence so customIdTokenClaims can override acr and auth_time without weakening core claims. Adds tests to lock this behavior, including nonce and sid.

  • Bug Fixes
    • @better-auth/oauth-provider: Move auth_time and acr before customIdTokenClaims in createIdToken so overrides work; keep iss, sub, aud, iat, and exp pinned.
    • Add tests verifying acr/auth_time are overridable and pinned claims are not, now also covering nonce and sid.

Written for commit f78ffd652f. 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/8633 **Author:** [@gustavovalverde](https://github.com/gustavovalverde) **Created:** 3/16/2026 **Status:** ✅ Merged **Merged:** 3/28/2026 **Merged by:** [@gustavovalverde](https://github.com/gustavovalverde) **Base:** `main` ← **Head:** `fix/oauth-provider-acr-auth-time-override` --- ### 📝 Commits (2) - [`8615f09`](https://github.com/better-auth/better-auth/commit/8615f09b4627839ffb0d2129060c400cd7ed4fd1) fix(oauth-provider): let customIdTokenClaims override acr and auth_time - [`f78ffd6`](https://github.com/better-auth/better-auth/commit/f78ffd652f76c44e8a38c3d5821a27e6df65e755) test(oauth-provider): cover nonce and sid in pinned claims test ### 📊 Changes **2 files changed** (+146 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/oauth-provider/src/token.test.ts` (+145 -0) 📝 `packages/oauth-provider/src/token.ts` (+1 -1) </details> ### 📄 Description ## Problem Follow-up to #7865, which fixed the ordering of `userClaims` vs `customClaims` so that `customIdTokenClaims` can override standard OIDC claims. That fix placed `...customClaims` after `...userClaims`, but `auth_time` and `acr` are assigned *after* the `customClaims` spread, silently overwriting any custom values. This matters for providers that compute `acr` dynamically (e.g., from MFA status or step-up authentication level) and need `customIdTokenClaims` to be the final authority. ## Changes In `createIdToken`, move `auth_time` and `acr` assignments before the `...customClaims` spread. The resulting order is: `userClaims` → `auth_time`/`acr` (defaults) → `customClaims` (overrides) → `iss`/`sub`/`aud`/`iat`/`exp` (non-overridable). One-line change. ## References - [OIDC Core §2 — ID Token `auth_time` and `acr` claims](https://openid.net/specs/openid-connect-core-1_0.html#IDToken) - #7865 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes ID token claim precedence so `customIdTokenClaims` can override `acr` and `auth_time` without weakening core claims. Adds tests to lock this behavior, including `nonce` and `sid`. - **Bug Fixes** - `@better-auth/oauth-provider`: Move `auth_time` and `acr` before `customIdTokenClaims` in `createIdToken` so overrides work; keep `iss`, `sub`, `aud`, `iat`, and `exp` pinned. - Add tests verifying `acr`/`auth_time` are overridable and pinned claims are not, now also covering `nonce` and `sid`. <sup>Written for commit f78ffd652f76c44e8a38c3d5821a27e6df65e755. 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-15 22:41:16 -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#25006