Implement authClient.linkOauth2 to enable linking generic OAuth providers #2924

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

Originally created by @baderj on GitHub (Feb 26, 2026).

Is this suited for github?

  • Yes, this is suited for github

Generic OAuth uses the sign-in method authClient.signIn.oauth2 as opposed to authClient.signIn.social for social sign-in of the built-in providers.

To link additional providers for an already logged in user there is authClient.linkSocial for social sign-in. A similar method authClient.linkOAuth2 is missing.

So currently it is not possible to link multiple generic OAuth2 providers:

  • Using authClient.signIn.oauth2 for an already signed in user will create a new user (even if allowDifferentEmail: true and the involved OAuth providers are listed as trustedProviders in the accountLinking settings).
  • Using authClient.linkSocial for a generic OAuth provider (such as Keycloak) will fail because the config is not used, e.g., the authorizationUrl is just a generic /oauth2/callback/ instead of the configured value. So the signin flow does not work.

Describe the solution you'd like

There should be a method authClient.linkOAuth2 to enable generic OAuth providers to be linked.

Describe alternatives you've considered

I considered writing my own logic to merge accounts in database hooks.

Additional context

No response

Originally created by @baderj on GitHub (Feb 26, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Generic OAuth uses the sign-in method `authClient.signIn.oauth2` as opposed to `authClient.signIn.social` for social sign-in of the built-in providers. To link additional providers for an already logged in user there is `authClient.linkSocial` for social sign-in. A similar method `authClient.linkOAuth2` is missing. So currently it is not possible to link multiple generic OAuth2 providers: - Using `authClient.signIn.oauth2` for an already signed in user will create a new user (even if `allowDifferentEmail: true` and the involved OAuth providers are listed as `trustedProviders` in the `accountLinking` settings). - Using `authClient.linkSocial` for a generic OAuth provider (such as Keycloak) will fail because the config is not used, e.g., the `authorizationUrl` is just a generic `/oauth2/callback/` instead of the configured value. So the signin flow does not work. ### Describe the solution you'd like There should be a method `authClient.linkOAuth2` to enable generic OAuth providers to be linked. ### Describe alternatives you've considered I considered writing my own logic to merge accounts in database hooks. ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 10:28:01 -05:00
Author
Owner

@baderj commented on GitHub (Feb 27, 2026):

Sorry I totally missed that authClient.oauth2.link exists as documented here.

The documentation User & Accounts -> Manually Linking only covers Linking Social Accounts and Linking Credential-Based Accounts, so maybe consider adding a third bullet point for Linking OAuth Accounts.

My apologies again. I should have reviewed the documentation more carefully.

@baderj commented on GitHub (Feb 27, 2026): Sorry I totally missed that `authClient.oauth2.link` exists as documented [here](https://www.better-auth.com/docs/plugins/generic-oauth#linking-oauth-accounts). The documentation [User & Accounts -> Manually Linking](https://www.better-auth.com/docs/concepts/users-accounts#manually-linking-accounts) only covers *Linking Social Accounts* and *Linking Credential-Based Accounts*, so maybe consider adding a third bullet point for *Linking OAuth Accounts*. My apologies again. I should have reviewed the documentation more carefully.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2924