[PR #8635] [CLOSED] feat(oauth-provider): auth_session passthrough for first-party app step-up #25008

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8635
Author: @gustavovalverde
Created: 3/16/2026
Status: Closed

Base: mainHead: feat/first-party-apps


📝 Commits (1)

  • 4f1a685 feat(oauth-provider): auth_session passthrough for first-party app step-up

📊 Changes

3 files changed (+193 additions, -1 deletions)

View changed files

📝 packages/oauth-provider/src/token.test.ts (+178 -1)
📝 packages/oauth-provider/src/token.ts (+9 -0)
📝 packages/oauth-provider/src/types/index.ts (+6 -0)

📄 Description

Context

This is a building block for draft-ietf-oauth-first-party-apps (Authorization Challenge Endpoint) support. It is not a complete FPA implementation; it adds one specific capability that the pattern requires.

Problem

First-party apps (CLI tools, native apps by the same provider) use an Authorization Challenge Endpoint to authenticate without browser redirects. When a protected action requires step-up re-authentication (e.g., a CIBA token exchange fails acr_values), the client needs a reference to its existing auth session to re-authenticate via the challenge endpoint rather than starting a new session.

The authorization code can carry this session reference (set by the challenge endpoint when issuing the code), but the token endpoint currently discards it. There is no mechanism to pass opaque metadata from the authorization code through to the token response.

Changes

  • Add optional authSession?: string field to VerificationValue type (the authorization code payload)
  • In handleAuthorizationCodeGrant, when verificationValue.authSession is set, inject auth_session into the token response body via the extra.tokenResponse mechanism

The challenge endpoint (not in this PR) sets authSession when creating the authorization code. The client receives it in the token response and uses it for subsequent challenge requests.

References


Summary by cubic

Adds auth_session passthrough in oauth-provider token responses to support first‑party app step‑up. When an auth code includes an authSession reference, the token response echoes it as auth_session.

  • New Features
    • Types: add authSession?: string to VerificationValue.
    • Token: if authSession is present, include auth_session in the token response; otherwise unchanged. createUserTokens now accepts extra.tokenResponse to merge custom fields.
    • Tests: cover inclusion and omission of auth_session in token responses.

Written for commit 4f1a685a52. 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/8635 **Author:** [@gustavovalverde](https://github.com/gustavovalverde) **Created:** 3/16/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/first-party-apps` --- ### 📝 Commits (1) - [`4f1a685`](https://github.com/better-auth/better-auth/commit/4f1a685a52a2ddd6c337e305650d5406ac72130c) feat(oauth-provider): auth_session passthrough for first-party app step-up ### 📊 Changes **3 files changed** (+193 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/oauth-provider/src/token.test.ts` (+178 -1) 📝 `packages/oauth-provider/src/token.ts` (+9 -0) 📝 `packages/oauth-provider/src/types/index.ts` (+6 -0) </details> ### 📄 Description ## Context This is a building block for `draft-ietf-oauth-first-party-apps` (Authorization Challenge Endpoint) support. It is not a complete FPA implementation; it adds one specific capability that the pattern requires. ## Problem First-party apps (CLI tools, native apps by the same provider) use an Authorization Challenge Endpoint to authenticate without browser redirects. When a protected action requires step-up re-authentication (e.g., a CIBA token exchange fails `acr_values`), the client needs a reference to its existing auth session to re-authenticate via the challenge endpoint rather than starting a new session. The authorization code can carry this session reference (set by the challenge endpoint when issuing the code), but the token endpoint currently discards it. There is no mechanism to pass opaque metadata from the authorization code through to the token response. ## Changes - Add optional `authSession?: string` field to `VerificationValue` type (the authorization code payload) - In `handleAuthorizationCodeGrant`, when `verificationValue.authSession` is set, inject `auth_session` into the token response body via the `extra.tokenResponse` mechanism The challenge endpoint (not in this PR) sets `authSession` when creating the authorization code. The client receives it in the token response and uses it for subsequent challenge requests. ## References - [draft-ietf-oauth-first-party-apps — Authorization Challenge Endpoint](https://datatracker.ietf.org/doc/draft-ietf-oauth-first-party-apps/) - [RFC 9470 — OAuth 2.0 Step-Up Authentication Challenge Protocol](https://datatracker.ietf.org/doc/html/rfc9470) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds `auth_session` passthrough in `oauth-provider` token responses to support first‑party app step‑up. When an auth code includes an `authSession` reference, the token response echoes it as `auth_session`. - **New Features** - Types: add `authSession?: string` to `VerificationValue`. - Token: if `authSession` is present, include `auth_session` in the token response; otherwise unchanged. `createUserTokens` now accepts `extra.tokenResponse` to merge custom fields. - Tests: cover inclusion and omission of `auth_session` in token responses. <sup>Written for commit 4f1a685a52a2ddd6c337e305650d5406ac72130c. 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:19 -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#25008