[GH-ISSUE #2765] Failed to get a valid access token: due to missing accessTokenExpiresAt and refreshToken #9340

Closed
opened 2026-04-13 04:46:36 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @stephenjason89 on GitHub (May 23, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2765

🐛 Bug Report

When using GitHub as a social provider, the login succeeds but subsequent calls to getAccessToken fail with the following error:
Failed to get a valid access token

🔍 Root Cause

GitHub does not return:

  • a refreshToken
  • an accessTokenExpiresAt

Because of this, Better Auth tries to refresh the token by default when using getAccessToken, even though it is not possible — leading to the failure.

Expected Behavior

For social providers like GitHub that:

  • issue long-lived access tokens
  • do not support token refresh

Better Auth should not attempt to refresh the token if accessTokenExpiresAt is null.

Originally created by @stephenjason89 on GitHub (May 23, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2765 ## 🐛 Bug Report When using GitHub as a social provider, the login succeeds but subsequent calls to `getAccessToken` fail with the following error: `Failed to get a valid access token` ## 🔍 Root Cause GitHub does **not** return: - a `refreshToken` - an `accessTokenExpiresAt` Because of this, Better Auth tries to refresh the token by default when using `getAccessToken`, even though it is not possible — leading to the failure. ## ✅ Expected Behavior For social providers like GitHub that: - issue long-lived access tokens - do not support token refresh Better Auth should **not attempt to refresh** the token if `accessTokenExpiresAt` is `null`.
GiteaMirror added the locked label 2026-04-13 04:46:36 -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#9340