[GH-ISSUE #2701] Github auth.api.getAccessToken is broken because Github doesn't supports refresh tokens #17939

Closed
opened 2026-04-15 16:18:04 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @madarco on GitHub (May 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2701

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  • Use the GitHub provider
  • login
  • then try:
await auth.api.getAccessToken({
      headers: await headers(),
      body: {
        providerId: "github",
      },
    });

Also in the Account table the access token expires at and refresh_token are null

Current vs. Expected behavior

A possible fix could be to change the logic in the /get-access-token API to not try to refresh the token if the the refresh_token or accessTokenExpiresAt are null

What version of Better Auth are you using?

1.2.8

Provide environment information

- OS: MacOs
- Node: v22.3.0

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  socialProviders: {
    github: {
      clientId: process.env.GITHUB_CLIENT_ID!,
      clientSecret: process.env.GITHUB_CLIENT_SECRET!,
      scope: ["repo", "read:user", "user:email"],
    }
  }
});

Additional context

No response

Originally created by @madarco on GitHub (May 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2701 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce - Use the GitHub provider - login - then try: ``` await auth.api.getAccessToken({ headers: await headers(), body: { providerId: "github", }, }); ``` Also in the Account table the access token expires at and refresh_token are null ### Current vs. Expected behavior A possible fix could be to change the logic in the /get-access-token API to not try to refresh the token if the the refresh_token or accessTokenExpiresAt are null ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - OS: MacOs - Node: v22.3.0 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ socialProviders: { github: { clientId: process.env.GITHUB_CLIENT_ID!, clientSecret: process.env.GITHUB_CLIENT_SECRET!, scope: ["repo", "read:user", "user:email"], } } }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 16:18:04 -05:00
Author
Owner

@alevidals commented on GitHub (May 24, 2025):

I’m not actually sure if the error is caused by what @madarco mentioned, but I’m unable to retrieve the access token using the auth.api.getAccessToken method. For now, I have to get it by accessing the database manually.

<!-- gh-comment-id:2906895173 --> @alevidals commented on GitHub (May 24, 2025): I’m not actually sure if the error is caused by what @madarco mentioned, but I’m unable to retrieve the access token using the auth.api.getAccessToken method. For now, I have to get it by accessing the database manually.
Author
Owner

@artemoire commented on GitHub (Jun 19, 2025):

From my investigation, a fix should have been released last week in v1.2.9
PR that (hopefully) fixed it: https://github.com/better-auth/better-auth/pull/2764

<!-- gh-comment-id:2989145660 --> @artemoire commented on GitHub (Jun 19, 2025): From my investigation, a fix should have been released last week in `v1.2.9` PR that (hopefully) fixed it: https://github.com/better-auth/better-auth/pull/2764
Author
Owner

@ping-maxwell commented on GitHub (Jul 8, 2025):

Hey guys, it looks like a fix is merged. I'll close this issue for now. If you guys are still experiencing this issue please do say, I'll re-open this!

<!-- gh-comment-id:3049443116 --> @ping-maxwell commented on GitHub (Jul 8, 2025): Hey guys, it looks like a fix is merged. I'll close this issue for now. If you guys are still experiencing this issue please do say, I'll re-open this!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17939