[PR #7210] [MERGED] fix(oauth): handle unencrypted tokens when encryptOAuthTokens is enabled #15394

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7210
Author: @Paola3stefania
Created: 1/8/2026
Status: Merged
Merged: 1/9/2026
Merged by: @Bekacru

Base: canaryHead: fix/decrypt-oauth-token-unencrypted-fallback


📝 Commits (3)

📊 Changes

2 files changed (+170 additions, -0 deletions)

View changed files

packages/better-auth/src/oauth2/utils.test.ts (+160 -0)
📝 packages/better-auth/src/oauth2/utils.ts (+10 -0)

📄 Description


Summary by cubic

Fixes decryption errors when encryptOAuthTokens is enabled by returning plain, unencrypted OAuth tokens as-is. Adds a simple check to detect encrypted tokens and comprehensive tests for migration scenarios.

  • Bug Fixes
    • Updated decryptOAuthToken to only decrypt hex-encoded, even-length tokens; non-encrypted tokens (e.g., Google/JWT-style) are returned as-is to avoid “hex string expected” errors.
    • Added tests covering empty tokens, disabled encryption, migration from unencrypted tokens (Google access/refresh tokens, JWT-style), and encrypt/decrypt round trips.

Written for commit e18b0ad88b. Summary will update on new commits.

closes https://github.com/better-auth/better-auth/issues/6018


🔄 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/7210 **Author:** [@Paola3stefania](https://github.com/Paola3stefania) **Created:** 1/8/2026 **Status:** ✅ Merged **Merged:** 1/9/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/decrypt-oauth-token-unencrypted-fallback` --- ### 📝 Commits (3) - [`79a744a`](https://github.com/better-auth/better-auth/commit/79a744a42d709a6e5c3286657e4ef3c557741234) fix: check if encryted - [`a987261`](https://github.com/better-auth/better-auth/commit/a987261bb7cd59479bbc27b4eae7d190951dcba3) make lint happy - [`e18b0ad`](https://github.com/better-auth/better-auth/commit/e18b0ad88b559feae57a248ddd6a59fb60fb08e2) spell happy ### 📊 Changes **2 files changed** (+170 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `packages/better-auth/src/oauth2/utils.test.ts` (+160 -0) 📝 `packages/better-auth/src/oauth2/utils.ts` (+10 -0) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes decryption errors when encryptOAuthTokens is enabled by returning plain, unencrypted OAuth tokens as-is. Adds a simple check to detect encrypted tokens and comprehensive tests for migration scenarios. - **Bug Fixes** - Updated decryptOAuthToken to only decrypt hex-encoded, even-length tokens; non-encrypted tokens (e.g., Google/JWT-style) are returned as-is to avoid “hex string expected” errors. - Added tests covering empty tokens, disabled encryption, migration from unencrypted tokens (Google access/refresh tokens, JWT-style), and encrypt/decrypt round trips. <sup>Written for commit e18b0ad88b559feae57a248ddd6a59fb60fb08e2. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> closes https://github.com/better-auth/better-auth/issues/6018 --- <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:00:45 -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#15394