Skip to content

Follow up to improve webauthn error messages - #51463

Open
uzmamansoor09 wants to merge 1 commit into
keycloak:mainfrom
uzmamansoor09:44963
Open

Follow up to improve webauthn error messages#51463
uzmamansoor09 wants to merge 1 commit into
keycloak:mainfrom
uzmamansoor09:44963

Conversation

@uzmamansoor09

@uzmamansoor09 uzmamansoor09 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Closes #44963.
Mapping some webauthn4j verifier exceptions to specific, localized error messages

Signed-off-by: uzmamansoor09 <Uzma.Mansoor@ibm.com>

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

Adds localized, verifier-specific WebAuthn error reporting for registration and authentication.

Changes:

  • Maps six webauthn4j verification exceptions to message keys.
  • Adds English messages and event/error handling.
  • Adds integration coverage and updates existing expectations.

Reviewed changes

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

Show a summary per file
File Description
themes/.../messages_en.properties Adds verifier-specific messages.
services/.../Messages.java Defines new message keys.
services/.../WebAuthnRegister.java Maps registration verifier failures.
services/.../WebAuthnAuthenticator.java Reports mapped authentication failures.
tests/.../WebAuthnErrorMessagesTest.java Tests mappings, events, and messages.
tests/.../WebAuthnPolicyComplianceTest.java Updates expected specific errors.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@uzmamansoor09
uzmamansoor09 marked this pull request as draft August 11, 2026 10:02
@uzmamansoor09
uzmamansoor09 marked this pull request as ready for review August 11, 2026 10:02

@rmartinc rmartinc 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.

Thanks @uzmamansoor09 for the PR! LGTM in general.

Please link the PR and the commit to the issue #44963 (add the Closes #44963 in your commit). I'm going to close the other PR saying that is superseded by this one.

I just added two nit-picks for your consideration. Not needed, just suggestion if you think that they are useful. I just added them because you need to change the commit to link the issue, so you need to modify the commit anyway.

Comment on lines +270 to +271
String messageKey = getWebAuthnErrorMessageKey(wae);
String errorCase = messageKey != null ? messageKey : WEBAUTHN_ERROR_AUTH_VERIFICATION;

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.

Nit-pick: You can just return WEBAUTHN_ERROR_AUTH_VERIFICATION or WEBAUTHN_ERROR_REGISTRATION as the default in the getWebAuthnErrorMessageKey and avoid this. You can pass a isRegistration parameter like in the other map method.

Comment on lines +348 to +349
String messageKey = getWebAuthnErrorMessageKey(wae);
String errorCase = messageKey != null ? messageKey : WEBAUTHN_ERROR_REGISTRATION;

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.

Same here. You can return WEBAUTHN_ERROR_REGISTRATION as the default in the method when isRegistration parameter is true in getWebAuthnErrorMessageKey.

/**
* Maps server side webauthn4j verifier exceptions to localizable Keycloak message keys
*/
public static String getWebAuthnErrorMessageKey(WebAuthnException exception) {

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.

You can add a boolean isRegistration parameter and return WEBAUTHN_ERROR_REGISTRATION or WEBAUTHN_ERROR_AUTH_VERIFICATION instead of null as the default.

Comment on lines +184 to +200
EventRepresentation event = null;

for (int i = 0; i < 10 && event == null; i++) {
EventRepresentation polled = events.poll();
if (polled == null) {
break;
}
if (polled.getDetails() != null && polled.getDetails().containsKey(errorLabel)) {
event = polled;
}
}

Assertions.assertNotNull(event, "No error event with detail '" + errorLabel + "' was found");

EventAssertion.assertError(event)
.error(expectedError)
.details(errorLabel, expectedMessageKey);

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.

Suggested change
EventRepresentation event = null;
for (int i = 0; i < 10 && event == null; i++) {
EventRepresentation polled = events.poll();
if (polled == null) {
break;
}
if (polled.getDetails() != null && polled.getDetails().containsKey(errorLabel)) {
event = polled;
}
}
Assertions.assertNotNull(event, "No error event with detail '" + errorLabel + "' was found");
EventAssertion.assertError(event)
.error(expectedError)
.details(errorLabel, expectedMessageKey);
EventAssertion.assertError(events.poll())
.error(expectedError)
.details(errorLabel, expectedMessageKey);

You are doing correctly the clear of the events. So I think you can just get the next event and check it is the expected one. I have tested it and it is working for me. WDYT?

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.

PassKey "User verification requirement" error's are not translated

4 participants