fix(auth): link bunyip_sub onto an existing verified-email account on SSO (LC-588) #551
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/LC-588-sso-email-link"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes LC-588 (origin BUNYIP-378): bunyip SSO sign-in failed with
sso_error=internalfor anyone who already had a Let's Chat account on the same email.Root cause (pinned from the server log)
The OIDC handshake succeeds.
resolve_or_provision_user(routes/bunyip_sso.rs) looks the user up bybunyip_sub, misses (a pre-SSO password account hasbunyip_sub = ''), thencreate_user_from_bunyipINSERTs a new row with the same email →UNIQUE(users.email)violation → internal error.Fix
Adopt the existing account by linking, instead of duplicate-inserting:
db::auth::link_bunyip_sub-UPDATE users SET bunyip_sub = ? ... WHERE id = ? AND (bunyip_sub IS NULL OR bunyip_sub = '') AND COALESCE(is_bot, 0) = 0, returning whether a row was linked. The guards mean it never overwrites a row already linked to another subject, and never links a bot.resolve_or_provision_user, after thebunyip_submiss and before auto-provision: ifuserinfo.email_verified == Some(true)and a non-empty email is present,find_user_id_by_email(already excludes banned) → on a hit,link_bunyip_sub→ on success, sign in as that user.Security
Linking by email is gated on
email_verified(bunyip issues it from the user's real verified status) so a bunyip account cannot claim an unverified address to hijack a local account. Banned/bot/already-linked rows are excluded. A verified-email collision already linked to a different subject is NOT auto-merged - it falls through (a genuine identity conflict).Testing
just checkgreen (server default + saas + desktop + clippy-D warnings+ fmt).just testpasses except 2 pre-existing failures inserver/tests/last_visited.rs(home-dashboard rendering) that are unrelated to this change and already fail onmain- confirmed by re-running them with this change stashed. Flagging separately; not introduced here.