Skip to content

Emit credential_id on UPDATE_CREDENTIAL events from built-in required actions - #50787

Open
nunofaria11 wants to merge 1 commit into
keycloak:mainfrom
getflip:enhance-update-credential-events-with-credential-id
Open

Emit credential_id on UPDATE_CREDENTIAL events from built-in required actions#50787
nunofaria11 wants to merge 1 commit into
keycloak:mainfrom
getflip:enhance-update-credential-events-with-credential-id

Conversation

@nunofaria11

Copy link
Copy Markdown

UpdatePassword, UpdateTotp and WebAuthnRegister now set Details.CREDENTIAL_ID on the generic UPDATE_CREDENTIAL event, matching REMOVE_CREDENTIAL which already carries the credential id. This lets event consumers identify which credential row was created or updated when a user has multiple credentials of the same type.

The OTP credential id is surfaced by hydrating it in OTPCredentialProvider.createCredential, consistent with PasswordCredentialProvider; password and WebAuthn ids are read from the credential lookup and the createCredential return value respectively.

Closes #50247

Aided by Claude Code (opus 4.8).

Copilot AI review requested due to automatic review settings July 10, 2026 12:48
@nunofaria11
nunofaria11 requested review from a team as code owners July 10, 2026 12:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Keycloak’s built-in credential required actions to include Details.CREDENTIAL_ID on UPDATE_CREDENTIAL events, aligning create/update-side auditing with existing REMOVE_CREDENTIAL behavior so event consumers can identify the exact credential row affected.

Changes:

  • Emit Details.CREDENTIAL_ID on UPDATE_CREDENTIAL for UpdatePassword, UpdateTotp, and WebAuthnRegister.
  • Hydrate OTP credential IDs by setting the created ID back onto the passed OTPCredentialModel during persistence.
  • Extend tests to assert credential_id is present (and for WebAuthn, equals the stored credential representation’s ID).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/WebAuthnIdlessTest.java Asserts UPDATE_CREDENTIAL includes Details.CREDENTIAL_ID matching the stored WebAuthn credential row.
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/actions/RequiredActionTotpSetupTest.java Asserts TOTP UPDATE_CREDENTIAL includes a non-null Details.CREDENTIAL_ID.
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/actions/AppInitiatedActionResetPasswordTest.java Asserts password UPDATE_CREDENTIAL includes a non-null Details.CREDENTIAL_ID.
services/src/main/java/org/keycloak/credential/OTPCredentialProvider.java Sets the generated credential ID back onto the input OTPCredentialModel after storing.
services/src/main/java/org/keycloak/authentication/requiredactions/WebAuthnRegister.java Captures created credential and emits its ID via Details.CREDENTIAL_ID.
services/src/main/java/org/keycloak/authentication/requiredactions/UpdateTotp.java Emits Details.CREDENTIAL_ID from the OTP credential model when available.
services/src/main/java/org/keycloak/authentication/requiredactions/UpdatePassword.java Looks up the password credential post-update and emits its ID via Details.CREDENTIAL_ID when available.

Copilot AI review requested due to automatic review settings July 14, 2026 16:45
@nunofaria11
nunofaria11 force-pushed the enhance-update-credential-events-with-credential-id branch from 7d01f41 to d7ea7a3 Compare July 14, 2026 16:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings July 15, 2026 07:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings July 15, 2026 07:26
@nunofaria11
nunofaria11 force-pushed the enhance-update-credential-events-with-credential-id branch from c5b2153 to 41adbd0 Compare July 15, 2026 07:26
@nunofaria11
nunofaria11 force-pushed the enhance-update-credential-events-with-credential-id branch from 41adbd0 to 3adb8b3 Compare July 15, 2026 07:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 15, 2026 07:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 15, 2026 08:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

@nunofaria11
nunofaria11 force-pushed the enhance-update-credential-events-with-credential-id branch 4 times, most recently from 515f705 to 85eefc5 Compare July 15, 2026 11:16
Copilot AI review requested due to automatic review settings July 15, 2026 11:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

… actions

UpdatePassword, UpdateTotp and WebAuthnRegister now set Details.CREDENTIAL_ID on the generic UPDATE_CREDENTIAL event, matching REMOVE_CREDENTIAL which already carries the credential id. This lets event consumers identify which credential row was created or updated when a user has multiple credentials of the same type.

The OTP credential id is surfaced by hydrating it in OTPCredentialProvider.createCredential, consistent with PasswordCredentialProvider; the WebAuthn id is read from the createCredential return value. For passwords, updateCredential only returns a boolean and the update may be handled entirely by a federated CredentialInputUpdater (e.g. LDAP in WRITABLE edit mode), so the id is emitted only when the local password row actually changed across the update: a local write creates a new row or re-stamps createdDate, while a federated write leaves any local row untouched.

Closes keycloak#50247

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Nuno Faria <nuno.faria@getflip.com>
Copilot AI review requested due to automatic review settings July 20, 2026 12:35
@nunofaria11
nunofaria11 force-pushed the enhance-update-credential-events-with-credential-id branch from 85eefc5 to 8f3253d Compare July 20, 2026 12:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UPDATE_CREDENTIAL events from built-in required actions omit credential_id (delete-side events already include it)

3 participants