Support custom tokenEndpointUrl & userInfoUrl configuration for proxy compatibility #941

Closed
opened 2026-03-13 08:10:49 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @ervinyan9 on GitHub (Mar 29, 2025).

Is this suited for github?

  • Yes, this is suited for github

Is your feature request related to a problem? Please describe.
When deploying in regions with network restrictions, we cannot directly access GitHub's default OAuth endpoints. The current fixed tokenEndpoint and userInfoEndpoint URLs prevent us from setting up proxy gateways for these API endpoints. This results in authentication failures in restricted network environments.

Describe the solution you'd like

Propose extending the configuration interface to accept custom endpoints:

interface GitHubProviderConfig {
  clientId: string
  clientSecret: string
  tokenEndpointUrl?: string  // Allow custom token endpoint
  userInfoUrl?: string       // Allow custom userinfo endpoint
}

This would enable proxy configurations like:

export const auth = betterAuth({
  socialProviders: {
    github: { 
      clientId: process.env.GH_CLIENT_ID,
      clientSecret: process.env.GH_CLIENT_SECRET,
      tokenEndpointUrl: "https://proxy.example.com/api/github/token",
      userInfoUrl: "https://proxy.example.com/api/github/userinfo"
    }
  }
})

Describe alternatives you've considered

Current workaround involves:

  1. Setting up reverse proxy endpoints
  2. Overriding fetch methods via monkey-patching:
const originalFetch = global.fetch
global.fetch = (url, init) => {
  if (url.toString().includes('github.com/login/oauth')) {
    url = new URL(url.toString().replace('github.com', 'proxy.example.com'))
  }
  return originalFetch(url, init)
}

This approach has significant drawbacks:
🔸 Introduces fragile network layer modifications
🔸 Causes side effects for non-auth requests
🔸 Requires additional infrastructure maintenance

Additional context

No response

Originally created by @ervinyan9 on GitHub (Mar 29, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. **Is your feature request related to a problem? Please describe.** When deploying in regions with network restrictions, we cannot directly access GitHub's default OAuth endpoints. The current fixed `tokenEndpoint` and `userInfoEndpoint` URLs prevent us from setting up proxy gateways for these API endpoints. This results in authentication failures in restricted network environments. ### Describe the solution you'd like Propose extending the configuration interface to accept custom endpoints: ```ts interface GitHubProviderConfig { clientId: string clientSecret: string tokenEndpointUrl?: string // Allow custom token endpoint userInfoUrl?: string // Allow custom userinfo endpoint } ``` This would enable proxy configurations like: ```ts export const auth = betterAuth({ socialProviders: { github: { clientId: process.env.GH_CLIENT_ID, clientSecret: process.env.GH_CLIENT_SECRET, tokenEndpointUrl: "https://proxy.example.com/api/github/token", userInfoUrl: "https://proxy.example.com/api/github/userinfo" } } }) ``` ### Describe alternatives you've considered Current workaround involves: 1. Setting up reverse proxy endpoints 2. Overriding fetch methods via monkey-patching: ```ts const originalFetch = global.fetch global.fetch = (url, init) => { if (url.toString().includes('github.com/login/oauth')) { url = new URL(url.toString().replace('github.com', 'proxy.example.com')) } return originalFetch(url, init) } ``` This approach has significant drawbacks: 🔸 Introduces fragile network layer modifications 🔸 Causes side effects for non-auth requests 🔸 Requires additional infrastructure maintenance ### Additional context _No response_
Author
Owner

@dosubot[bot] commented on GitHub (Jun 28, 2025):

Hi, @ervinyan9. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • Request for support of custom tokenEndpointUrl and userInfoUrl in GitHub OAuth provider.
  • Aimed at users facing network restrictions blocking GitHub's default endpoints.
  • Current workarounds are complex and unreliable.
  • No comments or activity since the issue was opened.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If no updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jun 28, 2025): Hi, @ervinyan9. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - Request for support of custom `tokenEndpointUrl` and `userInfoUrl` in GitHub OAuth provider. - Aimed at users facing network restrictions blocking GitHub's default endpoints. - Current workarounds are complex and unreliable. - No comments or activity since the issue was opened. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If no updates are provided, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#941