[PR #8276] [MERGED] fix(sso): prefer UserInfo endpoint over ID token and map sub claim correctly #7867

Closed
opened 2026-03-13 13:51:39 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8276
Author: @himself65
Created: 3/2/2026
Status: Merged
Merged: 3/2/2026
Merged by: @himself65

Base: canaryHead: fix/sso-userinfo-sub-claim


📝 Commits (5)

  • 3945faf fix(sso): use sub claim from UserInfo endpoint for OIDC compliance
  • 5155c5d test(sso): add test for UserInfo endpoint sub claim mapping
  • 9670704 Update sso.ts
  • 8e1cd01 lint fix
  • 2ec5cfd fix(sso): prefer UserInfo endpoint over ID token when available

📊 Changes

2 files changed (+176 additions, -34 deletions)

View changed files

📝 packages/sso/src/oidc.test.ts (+133 -3)
📝 packages/sso/src/routes/sso.ts (+43 -31)

📄 Description

Summary

  • The UserInfo endpoint fallback path was checking userInfo.id, but standard OIDC providers return sub (not id) as the subject identifier per OIDC spec Section 5.1
  • Applied the same claim mapping logic (subid, pictureimage, email_verifiedemailVerified, extraFields) to the UserInfo endpoint path that already existed for the ID token path
  • Updated the betterFetch generic type to Record<string, unknown> to accurately reflect raw OIDC UserInfo responses

Fixes #8269

Test plan

  • Verify SSO login works with an OIDC provider that does not include user claims in the ID token (e.g., Tinyauth)
  • Verify SSO login still works with providers that include claims in the ID token (existing behavior unchanged)
  • All existing SSO tests pass (pnpm vitest packages/sso/src --run)

🔄 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/8276 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/2/2026 **Status:** ✅ Merged **Merged:** 3/2/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/sso-userinfo-sub-claim` --- ### 📝 Commits (5) - [`3945faf`](https://github.com/better-auth/better-auth/commit/3945faf945285767c7295f1d232e5d061a019e85) fix(sso): use sub claim from UserInfo endpoint for OIDC compliance - [`5155c5d`](https://github.com/better-auth/better-auth/commit/5155c5d99744ea6e3b96b7cdc12a92ddb8b403f8) test(sso): add test for UserInfo endpoint sub claim mapping - [`9670704`](https://github.com/better-auth/better-auth/commit/967070412f3be9a1d20fdc2a819821e8a5e3f6c0) Update sso.ts - [`8e1cd01`](https://github.com/better-auth/better-auth/commit/8e1cd01691d1de526d6a1e290a62399133a6120a) lint fix - [`2ec5cfd`](https://github.com/better-auth/better-auth/commit/2ec5cfd456592b9f15fe0a3d8cb9f8067407b477) fix(sso): prefer UserInfo endpoint over ID token when available ### 📊 Changes **2 files changed** (+176 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `packages/sso/src/oidc.test.ts` (+133 -3) 📝 `packages/sso/src/routes/sso.ts` (+43 -31) </details> ### 📄 Description ## Summary - The UserInfo endpoint fallback path was checking `userInfo.id`, but standard OIDC providers return `sub` (not `id`) as the subject identifier per [OIDC spec Section 5.1](https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims) - Applied the same claim mapping logic (`sub`→`id`, `picture`→`image`, `email_verified`→`emailVerified`, `extraFields`) to the UserInfo endpoint path that already existed for the ID token path - Updated the `betterFetch` generic type to `Record<string, unknown>` to accurately reflect raw OIDC UserInfo responses Fixes #8269 ## Test plan - [ ] Verify SSO login works with an OIDC provider that does not include user claims in the ID token (e.g., Tinyauth) - [ ] Verify SSO login still works with providers that include claims in the ID token (existing behavior unchanged) - [ ] All existing SSO tests pass (`pnpm vitest packages/sso/src --run`) --- <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-03-13 13:51: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#7867