Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(auth): link OIDC sign-in to existing same-email accounts (#987)

Andrej0667479cb693
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index 218188e67..508bbeb29 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -180,6 +180,24 @@ export const auth = betterAuth({
},
},
},
+ account: {
+ accountLinking: {
+ // Link an OAuth/OIDC sign-in to an existing account that shares the same
+ // email instead of failing with error=account_not_linked. The listed
+ // providers verify the email on their side, so they are trusted to link.
+ enabled: true,
+ trustedProviders: ["github", "google", "discord", "custom"],
+ // Kaneo does not require email verification on password signup, so the
+ // existing local account is usually unverified; allow linking to it so
+ // OIDC users are not locked out.
+ // SECURITY: with open password registration this means someone who
+ // pre-registered a victim's email (unverified) could be linked into by
+ // that victim's OIDC login. Instances that allow password signup
+ // alongside OIDC should set DISABLE_PASSWORD_REGISTRATION or require email
+ // verification.
+ requireLocalEmailVerified: false,
+ },
+ },
emailAndPassword: {
enabled: true,
autoSignIn: true,
diff --git a/apps/docs/core/social-providers/custom-oauth.mdx b/apps/docs/core/social-providers/custom-oauth.mdx
index fb4d64143..b6a76829d 100644
--- a/apps/docs/core/social-providers/custom-oauth.mdx
+++ b/apps/docs/core/social-providers/custom-oauth.mdx
@@ -176,6 +176,12 @@ CUSTOM_OAUTH_DISCOVERY_URL=https://your-idp.com/.well-known/openid-configuration
This will automatically discover the authorization, token, and userinfo endpoints. However, you still need to provide the client ID and secret.
+## Account linking
+
+When a user signs in with this provider using an email that already belongs to a Kaneo account (for example one created with email and password), Kaneo links the OIDC identity to that existing account instead of failing with `error=account_not_linked`. GitHub, Google, Discord, and this custom provider are trusted to link because they verify the user's email.
+
+Because Kaneo does not require email verification on password signup, linking also applies to unverified local accounts so OIDC users are not locked out. If your instance allows password registration alongside OIDC, set `DISABLE_PASSWORD_REGISTRATION=true` (or require email verification) so that nobody can pre-register another person's email and have an OIDC login linked into it.
+
## Security Notes
- Always use HTTPS in production