Discovery in SSO OIDC registration is not used #1615

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

Originally created by @TheUntraceable on GitHub (Aug 1, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  • Register an SSO Provider with OIDC with only discovery and clientId and clientSecret
const ssoForm = useForm<SsoFormData>({
    resolver: zodResolver(ssoConfigSchema),
    mode: 'onChange',
    defaultValues: {
        issuer: '',
        clientId: '',
        clientSecret: '',
    },
});

const [handleSsoSubmit, isLoading] = useLoadingCallback(
    async (data: SsoFormData) => {
        if (!domain) {
            showErrorToast(
                'The company domain must be set to configure SSO.',
                'Please enter your company domain.'
            );
            return;
        }
        await authClient.sso.register({
            providerId,
            domain,
            oidcConfig: {
                ...data,
                discoveryEndpoint: `${data.issuer}/.well-known/openid-configuration`,
            },
            issuer: data.issuer,
            organizationId: organization.id,
            fetchOptions: {
                onSuccess: () => {
                    showSuccessToast(
                        'SSO Configuration Saved',
                        'Your SSO settings have been successfully saved.'
                    );
                    ssoForm.reset();
                    setDomain(''); // Reset form to initial state on success
                },
                onError: (context) => {
                    showErrorToast(context.error.message, '');
                },
            },
        });
    }
);

Current vs. Expected behavior

Expected: The Discovery URL should be used to fetch the data and store that in the database inside the oidcConfig
Current: The Discovery URL is stored in the database but other crucial data is not retrieved.

What version of Better Auth are you using?

1.3.0 (@better-auth/sso is at v1.3.4)

Provide environment information

- OS: Windows 11
- Browser: Brave

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

Package

Auth config (if applicable)


Additional context

No response

Originally created by @TheUntraceable on GitHub (Aug 1, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce - Register an SSO Provider with OIDC with only discovery and clientId and clientSecret ```ts const ssoForm = useForm<SsoFormData>({ resolver: zodResolver(ssoConfigSchema), mode: 'onChange', defaultValues: { issuer: '', clientId: '', clientSecret: '', }, }); const [handleSsoSubmit, isLoading] = useLoadingCallback( async (data: SsoFormData) => { if (!domain) { showErrorToast( 'The company domain must be set to configure SSO.', 'Please enter your company domain.' ); return; } await authClient.sso.register({ providerId, domain, oidcConfig: { ...data, discoveryEndpoint: `${data.issuer}/.well-known/openid-configuration`, }, issuer: data.issuer, organizationId: organization.id, fetchOptions: { onSuccess: () => { showSuccessToast( 'SSO Configuration Saved', 'Your SSO settings have been successfully saved.' ); ssoForm.reset(); setDomain(''); // Reset form to initial state on success }, onError: (context) => { showErrorToast(context.error.message, ''); }, }, }); } ); ``` ### Current vs. Expected behavior Expected: The Discovery URL should be used to fetch the data and store that in the database inside the oidcConfig Current: The Discovery URL is stored in the database but other crucial data is not retrieved. ### What version of Better Auth are you using? 1.3.0 (@better-auth/sso is at v1.3.4) ### Provide environment information ```bash - OS: Windows 11 - Browser: Brave ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the integration label 2026-03-13 08:51:37 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 1, 2025):

You're correct: during SSO OIDC provider registration, Better Auth only stores the discovery endpoint and other provided config fields in the database—it does not fetch or persist additional metadata from the discovery endpoint at registration time. The actual OIDC discovery (fetching endpoints like authorization, token, and userinfo) happens just-in-time during the SSO callback (sign-in) phase, and the fetched data is used in-memory for that authentication flow, not saved to the database. This is by design in the current implementation and matches what you observed (see code).

If you need those endpoints stored in the database, you'll have to fetch and populate them manually at registration, or extend the registration logic to do so. There isn't a built-in workaround for this in the current version (docs).

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Aug 1, 2025): <!-- Answer --> You're correct: during SSO OIDC provider registration, Better Auth only stores the discovery endpoint and other provided config fields in the database—it does not fetch or persist additional metadata from the discovery endpoint at registration time. The actual OIDC discovery (fetching endpoints like authorization, token, and userinfo) happens just-in-time during the SSO callback (sign-in) phase, and the fetched data is used in-memory for that authentication flow, not saved to the database. This is by design in the current implementation and matches what you observed ([see code](https://github.com/better-auth/better-auth/blob/b27221b3561478ae98ed5955fde51dfcf59d4a21/packages/better-auth/src/plugins/sso/index.ts)). If you need those endpoints stored in the database, you'll have to fetch and populate them manually at registration, or extend the registration logic to do so. There isn't a built-in workaround for this in the current version ([docs](https://better-auth.com/docs/plugins/generic-oauth)). <!-- 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/ab353400-a39c-4b51-834e-aa92e803eb7e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/ab353400-a39c-4b51-834e-aa92e803eb7e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/ab353400-a39c-4b51-834e-aa92e803eb7e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/ab353400-a39c-4b51-834e-aa92e803eb7e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/ab353400-a39c-4b51-834e-aa92e803eb7e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/ab353400-a39c-4b51-834e-aa92e803eb7e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/ab353400-a39c-4b51-834e-aa92e803eb7e?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&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/3728)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1615