fix(keycloak): keep email and names when writing user attributes #43

Merged
sharang merged 1 commits from fix/kc-user-put-keeps-profile into main 2026-09-28 07:44:46 +00:00
Owner

Bug

After "Repair sign-in" on staging (tenant sharna), the invite link failed in a private window with "invalid email address". The Keycloak user had email: null, no first or last name.

Cause

Keycloak 26 checks a user PUT against the declarative user profile and clears email, firstName, lastName when the body omits them. The registry wrote attributes with a body of only {attributes}. SyncTenantStatus runs after every status change and right after the reprovision invite, so it removed the address the mail had just been sent to. The VERIFY_EMAIL action then had no email to verify.

Staging has two users hit by this: the sharna admin and stage-demo-1156, which had a status change earlier.

Fix

New updateUserAttributes reads the full user representation, changes only attributes, and writes the whole representation back. SyncTenantStatus, ensureUserAttributes and SyncClaims use it.

Tests

  • A regression test: after all three writes, username, email, names, enabled, requiredActions and the other attributes are still there.
  • If nothing changed, nothing is written.
  • A failing GET is reported.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB

## Bug After \"Repair sign-in\" on staging (tenant `sharna`), the invite link failed in a private window with **\"invalid email address\"**. The Keycloak user had `email: null`, no first or last name. ## Cause Keycloak 26 checks a user `PUT` against the declarative user profile and **clears `email`, `firstName`, `lastName` when the body omits them**. The registry wrote attributes with a body of only `{attributes}`. `SyncTenantStatus` runs after every status change and right after the reprovision invite, so it removed the address the mail had just been sent to. The `VERIFY_EMAIL` action then had no email to verify. Staging has two users hit by this: the sharna admin and `stage-demo-1156`, which had a status change earlier. ## Fix New `updateUserAttributes` reads the full user representation, changes only `attributes`, and writes the whole representation back. `SyncTenantStatus`, `ensureUserAttributes` and `SyncClaims` use it. ## Tests - A regression test: after all three writes, username, email, names, enabled, requiredActions and the other attributes are still there. - If nothing changed, nothing is written. - A failing GET is reported. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang added 1 commit 2026-09-28 07:20:35 +00:00
fix(keycloak): keep email and names when writing user attributes
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 23m35s
ci / image (pull_request) Skipped
72be56d72a
Keycloak 26 validates a user PUT against the declarative user profile and
clears email, firstName and lastName when the body leaves them out. The
registry wrote attributes with a body of only {attributes}, so every status
sync wiped the members' email addresses. Reprovision syncs the status right
after the invitation goes out; the action link then failed with "invalid
email address".

Attribute writes now read the full user, change the attributes in it and
write the whole representation back (SyncTenantStatus, ensureUserAttributes,
SyncClaims).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang merged commit 485f3432ac into main 2026-09-28 07:44:46 +00:00
Sign in to join this conversation.