[PR #4064] [CLOSED] feat(oauth2): add raw provider response to OAuth2Tokens #5162

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4064
Author: @CaoMeiYouRen
Created: 8/18/2025
Status: Closed

Base: mainHead: fix/oauth2


📝 Commits (3)

📊 Changes

3 files changed (+46 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/oauth2/refresh-access-token.ts (+2 -0)
📝 packages/better-auth/src/oauth2/types.ts (+6 -0)
📝 packages/better-auth/src/oauth2/utils.ts (+38 -0)

📄 Description

Summary

Add raw provider response to OAuth2Tokens interface to expose additional provider-specific fields.

Changes Made

  • Enhanced OAuth2Tokens interface: Added an optional raw field to store the complete response from OAuth provider's token endpoint
  • Updated token handling: Modified getOAuth2Tokens() and refreshAccessToken() functions to include raw response data
  • Improved documentation: Added JSDoc comments explaining the purpose and usage of the new raw field

Motivation

OAuth providers often return additional fields in their token responses that are specific to their platform (e.g., openid, open_id, unionid for various providers). Currently, better-auth only extracts standard OAuth2 fields, potentially losing valuable provider-specific information that developers might need.

Benefits

  • Enhanced flexibility: Developers can now access all provider-specific fields returned by OAuth providers
  • Better debugging: Raw response data helps with troubleshooting OAuth integration issues
  • Future-proof: Supports new fields that providers might add without requiring library updates
  • Backward compatible: The new field is optional and doesn't break existing implementations

Files Modified

  • types.ts - Added raw field to OAuth2Tokens interface
  • utils.ts - Updated getOAuth2Tokens() to include raw data
  • refresh-access-token.ts - Updated token refresh logic to include raw data

Testing

This change maintains full backward compatibility as the new field is optional. Existing code will continue to work unchanged while new implementations can optionally access the raw provider response.


Summary by cubic

Expose the full OAuth provider token response via a new raw field on OAuth2Tokens. This lets apps access provider‑specific fields and helps debugging without breaking existing code.

  • New Features
    • Added raw?: Record<string, any> to OAuth2Tokens to store the full token response.
    • getOAuth2Tokens and refreshAccessToken now include raw in returned tokens.
    • Added JSDoc explaining raw and common provider-specific fields.

🔄 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/4064 **Author:** [@CaoMeiYouRen](https://github.com/CaoMeiYouRen) **Created:** 8/18/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/oauth2` --- ### 📝 Commits (3) - [`31a7364`](https://github.com/better-auth/better-auth/commit/31a73648e902c1944ef31d4e095c5bb925e4f72b) feat(oauth2): add raw provider response to OAuth2Tokens - [`43120a3`](https://github.com/better-auth/better-auth/commit/43120a346f05043bbbf9f3bb0f248f25c53575a3) Merge branch 'main' of https://github.com/better-auth/better-auth into fix/oauth2 - [`cfd787a`](https://github.com/better-auth/better-auth/commit/cfd787a37fb786f7448e62e9d7065dfc8611da2d) fix(oauth2): add filterSensitiveFields utility to sanitize OAuth response data ### 📊 Changes **3 files changed** (+46 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/oauth2/refresh-access-token.ts` (+2 -0) 📝 `packages/better-auth/src/oauth2/types.ts` (+6 -0) 📝 `packages/better-auth/src/oauth2/utils.ts` (+38 -0) </details> ### 📄 Description ### Summary Add raw provider response to OAuth2Tokens interface to expose additional provider-specific fields. ### Changes Made - **Enhanced `OAuth2Tokens` interface**: Added an optional `raw` field to store the complete response from OAuth provider's token endpoint - **Updated token handling**: Modified `getOAuth2Tokens()` and `refreshAccessToken()` functions to include raw response data - **Improved documentation**: Added JSDoc comments explaining the purpose and usage of the new `raw` field ### Motivation OAuth providers often return additional fields in their token responses that are specific to their platform (e.g., `openid`, `open_id`, `unionid` for various providers). Currently, better-auth only extracts standard OAuth2 fields, potentially losing valuable provider-specific information that developers might need. ### Benefits - **Enhanced flexibility**: Developers can now access all provider-specific fields returned by OAuth providers - **Better debugging**: Raw response data helps with troubleshooting OAuth integration issues - **Future-proof**: Supports new fields that providers might add without requiring library updates - **Backward compatible**: The new field is optional and doesn't break existing implementations ### Files Modified - types.ts - Added `raw` field to `OAuth2Tokens` interface - utils.ts - Updated `getOAuth2Tokens()` to include raw data - refresh-access-token.ts - Updated token refresh logic to include raw data ### Testing This change maintains full backward compatibility as the new field is optional. Existing code will continue to work unchanged while new implementations can optionally access the raw provider response. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Expose the full OAuth provider token response via a new raw field on OAuth2Tokens. This lets apps access provider‑specific fields and helps debugging without breaking existing code. - **New Features** - Added raw?: Record<string, any> to OAuth2Tokens to store the full token response. - getOAuth2Tokens and refreshAccessToken now include raw in returned tokens. - Added JSDoc explaining raw and common provider-specific fields. <!-- 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-03-13 12:12: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#5162