[PR #7873] [MERGED] fix(oauth-provider): support scope narrowing at consent submission #15851

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7873
Author: @gustavovalverde
Created: 2/9/2026
Status: Merged
Merged: 2/15/2026
Merged by: @Bekacru

Base: canaryHead: fix/oauth-consent-scope-narrowing-pr


📝 Commits (2)

  • ca196ed fix(oauth-provider): support scope narrowing at consent submission
  • af45f54 test(oauth-provider): assert narrowed scopes after consent token exchange

📊 Changes

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

View changed files

📝 packages/oauth-provider/src/consent.ts (+3 -0)
📝 packages/oauth-provider/src/oauth.test.ts (+101 -1)

📄 Description

Summary

Fixes #7871

When a user consents to fewer scopes than originally requested at the consent page, the consent endpoint now narrows the query scope to match the consented subset before issuing the authorization code.

Changes

  • consent.ts: After storing consent, narrow the query scope to match the consented scopes before calling authorizeEndpoint.

Test plan

  • All existing oauth-provider tests pass (175/175)
  • New test: RP requests openid profile email read:posts with prompt=consent, user consents to openid profile email → auth code is issued
  • Existing test: stored consent for openid profile email, new request adds offline_access → consent page shown

🔄 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/7873 **Author:** [@gustavovalverde](https://github.com/gustavovalverde) **Created:** 2/9/2026 **Status:** ✅ Merged **Merged:** 2/15/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/oauth-consent-scope-narrowing-pr` --- ### 📝 Commits (2) - [`ca196ed`](https://github.com/better-auth/better-auth/commit/ca196edbeaf8843888ded586cb93144b2f53482a) fix(oauth-provider): support scope narrowing at consent submission - [`af45f54`](https://github.com/better-auth/better-auth/commit/af45f544f24884b8478c0bc23aeb29e4df40ef59) test(oauth-provider): assert narrowed scopes after consent token exchange ### 📊 Changes **2 files changed** (+104 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/oauth-provider/src/consent.ts` (+3 -0) 📝 `packages/oauth-provider/src/oauth.test.ts` (+101 -1) </details> ### 📄 Description ## Summary Fixes #7871 When a user consents to fewer scopes than originally requested at the consent page, the consent endpoint now narrows the query scope to match the consented subset before issuing the authorization code. ### Changes - **`consent.ts`**: After storing consent, narrow the query scope to match the consented scopes before calling `authorizeEndpoint`. ## Test plan - [x] All existing oauth-provider tests pass (175/175) - [x] New test: RP requests `openid profile email read:posts` with `prompt=consent`, user consents to `openid profile email` → auth code is issued - [x] Existing test: stored consent for `openid profile email`, new request adds `offline_access` → consent page shown --- <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:15:55 -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#15851