[GH-ISSUE #3094] GitHub Social Provider fails to refresh access tokens when using a GitHub App #9471

Closed
opened 2026-04-13 04:56:53 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @artemoire on GitHub (Jun 19, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3094

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Configure socialProviders to use Github App credentials
  2. Github App has token expiration by default
  3. Sign in with socialProvider GitHub
  4. Wait for access token expiration (8hrs)
  5. Try to trigger code that calls auth.api.getAccessToken
  6. Get error "Failed to get valid access token"

Current vs. Expected behavior

I expected to get a valid access token, with better-auth refreshing the expired token, but it fails

What version of Better Auth are you using?

1.2.8

Provide environment information

- OS: Pop!_OS 22.04 LTS
- Browser: chrome

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

Client, Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
import { LibsqlDialect } from "@libsql/kysely-libsql";

const dialect = new LibsqlDialect({
  url: process.env.AUTH_DATABASE_URL,
  authToken: process.env.AUTH_DATABASE_TOKEN,
});

export const auth = betterAuth({
  database: {
    dialect,
    type: "sqlite",
  },
  socialProviders: {
    github: {
      clientId: process.env.GITHUB_CLIENT_ID,
      clientSecret: process.env.GITHUB_CLIENT_SECRET,
    },
  },
  plugins: [
    admin(),
    organization(),
    jwt({
      jwt: {
        definePayload(session) {
          return {
            userId: session.user.id,
            organizationId: session.session.activeOrganizationId,
          };
        },
      },
    }),
  ],
});

Additional context

refresh access token https://github.com/better-auth/better-auth/pull/1779 implementation specified wrong github token endpoint.

GitHub documentation states that the refresh token endpoint is on /access_token
https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens

I couldn't find any other resources on refreshing tokens, from what I gathered, only User Access Tokens generated by GitHub Apps can expire

Originally created by @artemoire on GitHub (Jun 19, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3094 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Configure socialProviders to use Github App credentials 2. Github App has token expiration by default 3. Sign in with socialProvider GitHub 4. Wait for access token expiration (8hrs) 5. Try to trigger code that calls auth.api.getAccessToken 6. Get error "Failed to get valid access token" ### Current vs. Expected behavior I expected to get a valid access token, with better-auth refreshing the expired token, but it fails ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - OS: Pop!_OS 22.04 LTS - Browser: chrome ``` ### Which area(s) are affected? (Select all that apply) Client, Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" import { LibsqlDialect } from "@libsql/kysely-libsql"; const dialect = new LibsqlDialect({ url: process.env.AUTH_DATABASE_URL, authToken: process.env.AUTH_DATABASE_TOKEN, }); export const auth = betterAuth({ database: { dialect, type: "sqlite", }, socialProviders: { github: { clientId: process.env.GITHUB_CLIENT_ID, clientSecret: process.env.GITHUB_CLIENT_SECRET, }, }, plugins: [ admin(), organization(), jwt({ jwt: { definePayload(session) { return { userId: session.user.id, organizationId: session.session.activeOrganizationId, }; }, }, }), ], }); ``` ### Additional context refresh access token https://github.com/better-auth/better-auth/pull/1779 implementation specified wrong github token endpoint. GitHub documentation states that the refresh token endpoint is on `/access_token` https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens I couldn't find any other resources on refreshing tokens, from what I gathered, only User Access Tokens generated by GitHub Apps can expire
GiteaMirror added the locked label 2026-04-13 04:56:53 -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#9471