[PR #5094] [MERGED] fix: getAcccessToken refresh should properly refresh when oauth tokens are encrypted #22671

Closed
opened 2026-04-15 21:12:28 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5094
Author: @bsklaroff
Created: 10/5/2025
Status: Merged
Merged: 10/15/2025
Merged by: @Bekacru

Base: canaryHead: fix/encrypted-token-refresh


📝 Commits (1)

  • 4661a66 fix: getAcccessToken refresh with encryptOAuthTokens=true

📊 Changes

1 file changed (+7 additions, -6 deletions)

View changed files

📝 packages/better-auth/src/api/routes/account.ts (+7 -6)

📄 Description

If the encryptOAuthTokens option is set to true, then the token refresh behavior within the getAccessToken route was broken in two ways:

  1. The refreshToken needed to be decrypted before calling provider.refreshAccessToken
  2. Once (1) was fixed, the new accessToken was returned from provider.refreshAccessToken, and saved to newTokens. But then, the code was calling decryptOAuthTokens on it, even though it's not encrypted, which was causing an error

This PR fixes both issues, and getAccessToken now works property when the encryptOAuthTokens option is set


Summary by cubic

Fixes getAccessToken to correctly handle encrypted OAuth tokens during refresh. Prevents errors when encryptOAuthTokens=true and restores working token refresh.

  • Bug Fixes
    • Decrypt refreshToken before calling provider.refreshAccessToken and save refreshed tokens via setTokenUtil.
    • Do not decrypt the provider’s new accessToken; only decrypt the stored accessToken when no refresh occurs.

🔄 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/5094 **Author:** [@bsklaroff](https://github.com/bsklaroff) **Created:** 10/5/2025 **Status:** ✅ Merged **Merged:** 10/15/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/encrypted-token-refresh` --- ### 📝 Commits (1) - [`4661a66`](https://github.com/better-auth/better-auth/commit/4661a666b260f080edd7d0ee8872f33dd45573af) fix: getAcccessToken refresh with encryptOAuthTokens=true ### 📊 Changes **1 file changed** (+7 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/account.ts` (+7 -6) </details> ### 📄 Description If the encryptOAuthTokens option is set to true, then the token refresh behavior within the getAccessToken route was broken in two ways: 1. The refreshToken needed to be decrypted before calling provider.refreshAccessToken 2. Once (1) was fixed, the new accessToken was returned from provider.refreshAccessToken, and saved to newTokens. But then, the code was calling decryptOAuthTokens on it, even though it's not encrypted, which was causing an error This PR fixes both issues, and getAccessToken now works property when the encryptOAuthTokens option is set <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes getAccessToken to correctly handle encrypted OAuth tokens during refresh. Prevents errors when encryptOAuthTokens=true and restores working token refresh. - **Bug Fixes** - Decrypt refreshToken before calling provider.refreshAccessToken and save refreshed tokens via setTokenUtil. - Do not decrypt the provider’s new accessToken; only decrypt the stored accessToken when no refresh occurs. <!-- 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 21:12:28 -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#22671