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

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3569
Author: @CaoMeiYouRen
Created: 7/23/2025
Status: Closed

Base: mainHead: fix/oauth2


📝 Commits (1)

  • 31a7364 feat(oauth2): add raw provider response to OAuth2Tokens

📊 Changes

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

View changed files

📝 packages/better-auth/src/oauth2/refresh-access-token.ts (+1 -0)
📝 packages/better-auth/src/oauth2/types.ts (+6 -0)
📝 packages/better-auth/src/oauth2/utils.ts (+1 -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

Added a raw field to the OAuth2Tokens interface to include the full provider token response, making provider-specific fields available to developers.

  • New Features
    • getOAuth2Tokens and refreshAccessToken now return the full raw response from the OAuth provider in the raw field.

🔄 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/3569 **Author:** [@CaoMeiYouRen](https://github.com/CaoMeiYouRen) **Created:** 7/23/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/oauth2` --- ### 📝 Commits (1) - [`31a7364`](https://github.com/better-auth/better-auth/commit/31a73648e902c1944ef31d4e095c5bb925e4f72b) feat(oauth2): add raw provider response to OAuth2Tokens ### 📊 Changes **3 files changed** (+8 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/oauth2/refresh-access-token.ts` (+1 -0) 📝 `packages/better-auth/src/oauth2/types.ts` (+6 -0) 📝 `packages/better-auth/src/oauth2/utils.ts` (+1 -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 Added a raw field to the OAuth2Tokens interface to include the full provider token response, making provider-specific fields available to developers. - **New Features** - getOAuth2Tokens and refreshAccessToken now return the full raw response from the OAuth provider in the raw field. <!-- 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:03:08 -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#4888