genericOAuth - authorizationUrl is not auto discovered when providing discoveryUrl #1467

Closed
opened 2026-03-13 08:41:51 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @tsachis on GitHub (Jul 6, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Using the genericOAuth plugin with discoveryUrl:

import { betterAuth } from "better-auth"
import { genericOAuth } from "better-auth/plugins"
 
export const auth = betterAuth({
    // ... other config options
    plugins: [ 
        genericOAuth({ 
            config: [ 
                { 
                    providerId: "provider-id", 
                    clientId: "test-client-id", 
                    clientSecret: "test-client-secret", 
                    discoveryUrl: "https://auth.example.com/.well-known/openid-configuration",
                    // ... other config options
                }, 
                // Add more providers as needed
            ] 
        }) 
    ]
})

Then try to authenticate, using handler for example

await auth.handler(request);

an error is thrown:

TypeError: Invalid URL

Current vs. Expected behavior

  • Current
    Authorization fails with TypeError: Invalid URL since the authorization URL is not set.
    When adding the authorizationUrl property to the above config it works properly.

  • Expected
    authorizationUrl should be set automatically when using discoveryUrl

What version of Better Auth are you using?

1.2.12

Provide environment information

- OS: MACOS

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @tsachis on GitHub (Jul 6, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Using the `genericOAuth` plugin with `discoveryUrl`: ``` import { betterAuth } from "better-auth" import { genericOAuth } from "better-auth/plugins" export const auth = betterAuth({ // ... other config options plugins: [ genericOAuth({ config: [ { providerId: "provider-id", clientId: "test-client-id", clientSecret: "test-client-secret", discoveryUrl: "https://auth.example.com/.well-known/openid-configuration", // ... other config options }, // Add more providers as needed ] }) ] }) ``` Then try to authenticate, using `handler` for example ``` await auth.handler(request); ``` an error is thrown: ``` TypeError: Invalid URL ``` ### Current vs. Expected behavior - Current Authorization fails with `TypeError: Invalid URL` since the authorization URL is not set. When adding the `authorizationUrl` property to the above config it works properly. - Expected `authorizationUrl` should be set automatically when using `discoveryUrl` ### What version of Better Auth are you using? 1.2.12 ### Provide environment information ```bash - OS: MACOS ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
Author
Owner

@dosubot[bot] commented on GitHub (Jul 6, 2025):

Hi @tsachis! I'm Dosu and I’m helping the better-auth team.

The current implementation of the genericOAuth plugin does not auto-populate authorizationUrl from discoveryUrl. Even though the discovery document is fetched and token/userinfo endpoints are extracted, authorizationUrl still needs to be set explicitly in your config for things to work as expected. This matches the error you're seeing and is confirmed by the code and recent pull requests—auto-discovery for authorizationUrl isn't fully supported yet and must be provided manually for now [source] [source].

As a workaround, keep specifying authorizationUrl directly in your config when using discoveryUrl. If auto-discovery is important for your workflow, you might want to track or request this as a feature in future releases.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 6, 2025): <!-- Greeting --> Hi @tsachis! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The current implementation of the genericOAuth plugin does not auto-populate authorizationUrl from discoveryUrl. Even though the discovery document is fetched and token/userinfo endpoints are extracted, authorizationUrl still needs to be set explicitly in your config for things to work as expected. This matches the error you're seeing and is confirmed by the code and recent pull requests—auto-discovery for authorizationUrl isn't fully supported yet and must be provided manually for now [[source]](https://github.com/better-auth/better-auth/blob/2734d07e88f78e4e79f8bb65e909c297c7197a09/packages/better-auth/src/plugins/generic-oauth/index.ts) [[source]](https://github.com/better-auth/better-auth/pull/815). As a workaround, keep specifying authorizationUrl directly in your config when using discoveryUrl. If auto-discovery is important for your workflow, you might want to track or request this as a feature in future releases. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/46f75019-473f-4465-b2ea-d4acdbb36c0d?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/46f75019-473f-4465-b2ea-d4acdbb36c0d?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/46f75019-473f-4465-b2ea-d4acdbb36c0d?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/46f75019-473f-4465-b2ea-d4acdbb36c0d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/46f75019-473f-4465-b2ea-d4acdbb36c0d?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/46f75019-473f-4465-b2ea-d4acdbb36c0d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/46f75019-473f-4465-b2ea-d4acdbb36c0d?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3278)
Author
Owner

@cflee commented on GitHub (Sep 12, 2025):

I just ran into this with v1.3.9, so the issue is still present, but specifically only when calling authClient.signIn.social({ provider: providerId }) instead of what seems to be the documented authClient.signIn.oauth2({ providerId: providerId }).

I think it is due to this line that directly pulls authorizationUrl from the config without going through discovery (and with an ! to force it), put in place since #815 (v1.0.11). That change introduced a different code path where if you use /sign-in/social it does not perform discovery to get the authorization endpoint, while using the /sign-in/oauth2 it does perform discovery to get the authorization endpoint.

It would be nice if we could use the same authClient.signIn.social() for genericOAuth providers. After all, it seems that both socialProviders configs and genericOAuth configs are loaded onto the same socialProviders array in the AuthContext.

@cflee commented on GitHub (Sep 12, 2025): I just ran into this with v1.3.9, so the issue is still present, but specifically **only when calling `authClient.signIn.social({ provider: providerId })`** instead of what seems to be [the documented](https://www.better-auth.com/docs/plugins/generic-oauth) `authClient.signIn.oauth2({ providerId: providerId })`. I think it is [due to this line](https://github.com/better-auth/better-auth/blob/v1.3.9/packages/better-auth/src/plugins/generic-oauth/index.ts#L224) that directly pulls `authorizationUrl` from the config without going through discovery (and with an `!` to force it), put in place since #815 (v1.0.11). That change introduced a different code path where if you use `/sign-in/social` it [does not perform discovery](https://github.com/better-auth/better-auth/blob/7714d7398cb9001984abbc742bd15e4682c80381/packages/better-auth/src/plugins/generic-oauth/index.ts#L188) to get the authorization endpoint, while using the `/sign-in/oauth2` it [does perform discovery](https://github.com/better-auth/better-auth/blob/7714d7398cb9001984abbc742bd15e4682c80381/packages/better-auth/src/plugins/generic-oauth/index.ts#L349) to get the authorization endpoint. It would be nice if we could use the same `authClient.signIn.social()` for genericOAuth providers. After all, it seems that both socialProviders configs and genericOAuth configs are loaded onto the same `socialProviders` array in the AuthContext.
Author
Owner

@galsever commented on GitHub (Nov 14, 2025):

thank you for finding this. I had the same issue

@galsever commented on GitHub (Nov 14, 2025): thank you for finding this. I had the same issue
Author
Owner

@dosubot[bot] commented on GitHub (Feb 13, 2026):

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

Issue Summary:

  • You reported that in Better Auth v1.2.12, the genericOAuth plugin does not auto-set authorizationUrl from discoveryUrl, causing a "TypeError: Invalid URL" unless authorizationUrl is manually provided.
  • It was confirmed that this behavior is currently by design, as auto-discovery for authorizationUrl is not fully supported yet.
  • You and other users noted that in v1.3.9, the issue persists specifically when using authClient.signIn.social(), which bypasses discovery, unlike authClient.signIn.oauth2() that performs discovery.
  • There is a suggestion to unify these methods to allow social() to support genericOAuth providers with auto-discovery.
  • Other users have also confirmed experiencing the same problem.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • Otherwise, I will automatically close this issue in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Feb 13, 2026): Hi, @tsachis. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that in Better Auth v1.2.12, the genericOAuth plugin does not auto-set `authorizationUrl` from `discoveryUrl`, causing a "TypeError: Invalid URL" unless `authorizationUrl` is manually provided. - It was confirmed that this behavior is currently by design, as auto-discovery for `authorizationUrl` is not fully supported yet. - You and other users noted that in v1.3.9, the issue persists specifically when using `authClient.signIn.social()`, which bypasses discovery, unlike `authClient.signIn.oauth2()` that performs discovery. - There is a suggestion to unify these methods to allow `social()` to support genericOAuth providers with auto-discovery. - Other users have also confirmed experiencing the same problem. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - Otherwise, I will automatically close this issue 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#1467