feat(sso): Add a single RedirectURI for all providers to share #2788

Closed
opened 2026-03-13 10:20:17 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @OscarCornish on GitHub (Jan 29, 2026).

Originally assigned to: @Paola3stefania on GitHub.

Is this suited for github?

  • Yes, this is suited for github

Is your feature request related to a problem? Please describe.

I'm trying to migrate our SSO users from AWS Cognito without them needing to change their configurations, my complication here is that in AWS Cognito we have X SSO providers configured, and they all point to the same login.foo/callback redirectURI

I can point this url to my backend, but obviously better-auth is still expecting a providerId to be supplied on this request.

For SAML, I've managed to work around this with hooks - I can encode the provider Id into the state and use a 'unified' ACS Url, which effectively just unencodes the provider from the state and forwards it to the BA endpoint.

With OIDC its unfortunately not possible at the moment, as when the request is made to the token endpoint the redirectURI is passed, which is hardcoded as /api/auth/sso/callback/ . You could include the providerId in the verification table, given the code_verifier is already there and both are used in the token request.

I saw that there is some work being done of SSO at the moment, would this fit into that?

Describe the solution you'd like

In a perfect world, I could just do pass in the redirectURI (as a path) into the SSOOptions object and all providers would go via that endpoint (storing the providerId in the verification state instead of the path).

Describe alternatives you've considered

If the better-auth library didn't want to adopt the unified redirectURI, then just allowing the change of callback path would be enough (if done in the right way)

I already have the logic implemented using hooks to store the providerId in the state, the only issue is the OIDC token request has a hardcoded redirectURI.

If I could pass the redirectURI path into the options, and the redirectURI that is used in the token request simply tries to path.replace(":providerId", providerId), then I could pass in my providerId-less path and it would work just fine.

Additional context

This is a really high priority issue for me & my Team, that is blocking our migration to better-auth. I do have a corresponding discord feature request

Originally created by @OscarCornish on GitHub (Jan 29, 2026). Originally assigned to: @Paola3stefania on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I'm trying to migrate our SSO users from AWS Cognito without them needing to change their configurations, my complication here is that in AWS Cognito we have X SSO providers configured, and they all point to the same login.foo/callback redirectURI I can point this url to my backend, but obviously better-auth is still expecting a providerId to be supplied on this request. For SAML, I've managed to work around this with hooks - I can encode the provider Id into the state and use a 'unified' ACS Url, which effectively just unencodes the provider from the state and forwards it to the BA endpoint. With OIDC its unfortunately not possible at the moment, as when the request is made to the token endpoint the redirectURI is passed, which is hardcoded as <baseUrl>/api/auth/sso/callback/<providerId> . You could include the providerId in the verification table, given the code_verifier is already there and both are used in the token request. I saw that there is some work being done of SSO at the moment, would this fit into that? ### Describe the solution you'd like In a perfect world, I could just do pass in the redirectURI (as a path) into the SSOOptions object and all providers would go via that endpoint (storing the providerId in the verification state instead of the path). ### Describe alternatives you've considered If the better-auth library didn't want to adopt the unified redirectURI, then just allowing the change of callback path would be enough (if done in the right way) I already have the logic implemented using hooks to store the providerId in the state, the only issue is the OIDC token request has a hardcoded redirectURI. If I could pass the redirectURI path into the options, and the redirectURI that is used in the token request simply tries to `path.replace(":providerId", providerId)`, then I could pass in my providerId-less path and it would work just fine. ### Additional context This is a really high priority issue for me & my Team, that is blocking our migration to better-auth. I do have a corresponding [discord feature request](https://discord.com/channels/1288403910284935179/1466373232407085231)
GiteaMirror added the enhancement label 2026-03-13 10:20:17 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 29, 2026):

It looks like you're dealing with a challenge regarding the use of a single RedirectURI for multiple providers in Better Auth. Currently, Better Auth requires the providerId to be included in the redirect URI, like /api/auth/sso/callback/:providerId, which can complicate setups where this isn't feasible, as in your case with AWS Cognito [1][2].

Your request for a feature that allows a single redirect URI that all providers could share sounds like a useful enhancement. While such a feature could simplify migrations and configurations, it appears that there is an ongoing discussion and development around SSO that could possibly involve improved handling of redirect URIs and provider IDs, but specifics on support for your exact use case may not be finalized yet [3].

If you're looking for immediate solutions, your workaround with hooks for SAML is great, but for OIDC, you may want to tag @bekacru and @ping__ (Max) to get their insights on whether this feature can be prioritized or if there are alternative approaches you might not have considered.

What do you think about pursuing a different architecture for the token requests, or are there other features in Better Auth you're eager to explore?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 29, 2026): It looks like you're dealing with a challenge regarding the use of a single RedirectURI for multiple providers in Better Auth. Currently, Better Auth requires the `providerId` to be included in the redirect URI, like `/api/auth/sso/callback/:providerId`, which can complicate setups where this isn't feasible, as in your case with AWS Cognito [[1]](https://www.better-auth.com/docs/plugins/sso)[[2]](https://github.com/better-auth/better-auth/pull/6021). Your request for a feature that allows a single redirect URI that all providers could share sounds like a useful enhancement. While such a feature could simplify migrations and configurations, it appears that there is an ongoing discussion and development around SSO that could possibly involve improved handling of redirect URIs and provider IDs, but specifics on support for your exact use case may not be finalized yet [[3]](https://github.com/better-auth/better-auth/pull/4764). If you're looking for immediate solutions, your workaround with hooks for SAML is great, but for OIDC, you may want to tag @bekacru and @ping__ (Max) to get their insights on whether this feature can be prioritized or if there are alternative approaches you might not have considered. What do you think about pursuing a different architecture for the token requests, or are there other features in Better Auth you're eager to explore? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@Paola3stefania commented on GitHub (Feb 6, 2026):

@OscarCornish ty for your sugestion. we are on working in this :)

@Paola3stefania commented on GitHub (Feb 6, 2026): @OscarCornish ty for your sugestion. we are on working in this :)
Author
Owner

@ping-maxwell commented on GitHub (Feb 11, 2026):

Hello all, we're moving all feature requests or enhancement issues over to Github Discussions.

I've went ahead and created the discussion here:

https://github.com/better-auth/better-auth/discussions/7921

@ping-maxwell commented on GitHub (Feb 11, 2026): Hello all, we're moving all feature requests or enhancement issues over to Github Discussions. I've went ahead and created the discussion here: https://github.com/better-auth/better-auth/discussions/7921
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2788