Repository navigation
Conversation
The Configure OTP required action shows "Invalid authenticator code" when the submitted code does not match the new secret, but it emits no event. A failed OTP setup therefore leaves no trace in the event store or in event listeners, while Update Password and WebAuthn Register emit an error event when they reject the submitted credential. Emit UPDATE_CREDENTIAL_ERROR with error invalid_user_credentials on both branches that reject the code. invalid_user_credentials is the error the OTP login form records for a wrong code. The deprecated UPDATE_TOTP_ERROR is not emitted, as it is scheduled for removal. A blank code, a missing device name and a duplicate device name stay without an event: they are form validation and no code is checked. Closes keycloak#55639 Signed-off-by: Geremia Taglialatela <tagliala.dev@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Closes #55639
Problem
The Configure OTP required action (
UpdateTotp) shows "Invalid authenticator code." when the submitted code does not match the new secret, but it emits no event. A failed OTP setup leaves no trace in the event store or in event listeners. Update Password and WebAuthn Register emit an error event when they reject the submitted credential. Without it, an administrator cannot tell whether a user who fails to complete the setup entered a wrong code or never submitted one.Change
UpdateTotp.processActionalready sets the event type toUPDATE_CREDENTIAL. On the two branches that reject the code, it now calls:EventBuilder.errorappends_ERRORto the type, so this storesUPDATE_CREDENTIAL_ERROR. It carriescredential_type=otpand the user, client and login details already on the builder, for exampleusernameandcode_id.invalid_user_credentialsis what the OTP login form records for a wrong code, and what WebAuthn Register records when it rejects a registration response. No newErrorsconstant is added.UPDATE_TOTP_ERRORis not emitted. Remove deprecated event types for password/otp update or removal #32685 removes the deprecated event types, and one event per failed attempt keeps the volume down. It can be added to mirror Update Password if reviewers prefer.CredentialHelper.createOTPCredentialreturnsfalse. Both show the same "Invalid authenticator code." message.No new event type, no admin console change, no API change.
Tests
RequiredActionTotpSetupTest#setupTotpRegisteralready submits a wrong code. It now asserts theUPDATE_CREDENTIAL_ERRORevent withinvalid_user_credentialsandcredential_type=otpbefore the success events.UserStorageOTPTest#testUpdateOTPsubmits a code the new secret rejects. It now clears the queued error event, so its nextUPDATE_TOTPassertion reads the success event.Test status
Run on a full local build of this branch (
./mvnw clean install -DskipTests, thenspotless:check, both successful):RequiredActionTotpSetupTest,AppInitiatedActionTotpSetupTestandUserStorageOTPTestpass with the change: 33 tests, 0 failures, 0 errors (-Pauth-server-quarkus).RequiredActionTotpSetupTest#setupTotpRegisterfails without theUpdateTotpchange (NullPointerException: the expected error event is not queued) and passes with it.UserStorageOTPTest#testUpdateOTPpasses with and without the change. Its edit only clears the new error event from the queue, so the followingUPDATE_TOTPassertion still reads the success event. It does not assert the new event itself.Before/After screenshots
The two screenshots (Events > User events, before and after) are attached in the first comment.
Same steps, data and window size on both builds: a realm with user events enabled, the user has the required action Configure OTP, and submits the wrong code
000000twice.Before (26.8.2): Events > User events lists nothing.
After (this PR): Events > User events lists one
UPDATE_CREDENTIAL_ERRORper wrong code, with errorinvalid_user_credentials.Compatibility
UPDATE_CREDENTIAL_ERRORtoinclude-eventsnow get those events for OTP setup failures too.UPDATE_CREDENTIAL_ERRORnow also receivecredential_type=otpentries.AI assistance
An AI coding agent drafted this change, its tests and this description from a prompt.
🤖 Generated with Claude Code