Repository navigation
feat(identity): admin link-existing + unlink credential — fixes Ahmed + Pia (#291) - #3744
Merged
Merged
Conversation
Three new admin operations on /api/admin/users/:userId/credentials: GET /credentials — list bindings for this user's identity POST /credentials — bind an EXISTING WorkOS user by id DELETE /credentials/:credentialId — unbind (creates fresh singleton identity) POST bypasses createUser entirely, which fixes the case Brian hit on Ahmed: WorkOS still had user_01KG39QAWFMHE22MVT3XB6289S alive at [email protected] (the April merge's delete-secondary call had silently failed), so createUser returned 400 "Could not create user." Workflow is now: find the existing WorkOS user id in the WorkOS Dashboard, paste into "Link existing WorkOS user." DELETE is the unbind half — non-destructive (WorkOS user stays alive). Closes the Pia escalation (#291: "I want to remove a linked email"). Refuses on the primary credential to keep the host signed-in. UI on /admin/people detail panel now shows the bound credentials list with per-row Remove buttons (non-primary only), plus a "+ Link existing WorkOS user" action alongside "+ Add sign-in email." Existing /linked-emails (create-and-bind) error handler now surfaces the real WorkOS error message instead of a generic "502 upstream" — including the 400-BadRequest-on-already-exists case — and points admins at the new "Link existing" tool. Closes #3719 (admin consolidate-existing path). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Security review caught three improvements (no blockers):
M1 — silent consolidation foot-gun. POST /credentials would happily move
all of a credential's app-state (org memberships, working-group memberships,
certification work, community points) onto the host without distinguishing
"fresh credential" from "real account being absorbed." Now refuses with
409 + consolidate_confirmation_required when cred has app-state, requiring
{"consolidate": true} in the body to proceed. UI escalates the prompt and
makes admin type CONSOLIDATE in caps to confirm.
M2 — audit forensics. unbind_credential audit row now records
acting_workos_user_id (the actual auth credential, separate from the
post-id-swap canonical id) in details so admins with multiple bound
credentials are distinguishable. Issue #3717 still tracks the broader
audit-log overhaul; this is the local fix.
L1 — unbind UI confirmation now requires typing the credential's email
exactly, matching the strength of the link confirmation. Defends against
admin accidentally removing the wrong credential.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Semgrep flagged the (err as Error).message echo in the link/unlink error paths — defense-in-depth concern noted in the security review (L2). Removed; the full error is still logged via logger.error. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Aug 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three new admin endpoints + UI on `/admin/people` detail panel that close the gap exposed by Brian's first attempt to fix Ahmed: WorkOS rejected `createUser` for `[email protected]` with 400 BadRequest because the prior April merge's delete-secondary call had silently failed and the gmail WorkOS user is still alive (sign-in count 5, last sign-in Apr 27). The new "Link existing WorkOS user" path bypasses `createUser` entirely.
Also closes Pia's escalation #291 ("ability to unlink/remove a linked email") via the DELETE endpoint, and addresses #3719 (admin consolidate-existing flow).
What changes
`server/src/routes/admin/users.ts`
`server/public/admin-people.html` detail panel
How this fixes Ahmed
How this fixes Pia
`/admin/people` → Pia → her credential row → Remove → confirm. Email is no longer associated with her account; the WorkOS user remains so she can use it for a fresh AAO account if desired.
Test plan
Step 2 (separate PR, deferred per Brian)
Rename `/admin/users` → `/admin/credentials` and re-cleave the admin nav so identity/credential management lives in one place and `/admin/people` becomes purely the relationship view. Tracked separately.
🤖 Generated with Claude Code