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

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

Original Pull Request: https://github.com/better-auth/better-auth/pull/8633

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8633 **State:** closed **Merged:** Yes --- ## 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. -->
GiteaMirror added the pull-request label 2026-04-13 10:30:03 -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#16352