8000 Emit error event when OTP setup code is invalid by tagliala · Pull Request #55640 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
8000
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.keycloak.credential.CredentialProvider;
import org.keycloak.credential.OTPCredentialProvider;
import org.keycloak.events.Details;
import org.keycloak.events.Errors;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.AuthenticationExecutionModel;
Expand Down Expand Up @@ -136,6 +137,7 @@ public void processAction(RequiredActionContext context) {
.addError(new FormMessage(Validation.FIELD_OTP_CODE, Messages.INVALID_TOTP))
.createResponse(UserModel.RequiredAction.CONFIGURE_TOTP);
context.challenge(challenge);
event.error(Errors.INVALID_USER_CREDENTIALS);
return;
}
OTPCredentialProvider otpCredentialProvider = (OTPCredentialProvider) context.getSession().getProvider(CredentialProvider.class, "keycloak-otp");
Expand All @@ -162,6 +164,7 @@ public void processAction(RequiredActionContext context) {
.addError(new FormMessage(Validation.FIELD_OTP_CODE, Messages.INVALID_TOTP))
.createResponse(UserModel.RequiredAction.CONFIGURE_TOTP);
context.challenge(challenge);
event.error(Errors.INVALID_USER_CREDENTIALS);
return;
}
} catch (ModelDuplicateException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.keycloak.authentication.authenticators.browser.RecoveryAuthnCodesFormAuthenticatorFactory;
import org.keycloak.authentication.requiredactions.UpdateTotp;
import org.keycloak.events.Details;
import org.keycloak.events.Errors;
import org.keycloak.events.EventType;
import org.keycloak.models.AuthenticationExecutionModel;
import org.keycloak.models.UserModel;
Expand Down Expand Up @@ -186,6 +187,12 @@ public void setupTotpRegister() {
totpPage.configure("wrongOtp");
totpPage.assertCurrent();

EventAssertion.assertError(events.poll()).type(EventType.UPDATE_CREDENTIAL_ERROR)
.userId(userId)
.error(Errors.INVALID_USER_CREDENTIALS)
.details(Details.CREDENTIAL_TYPE, OTPCredentialModel.TYPE)
.details(Details.USERNAME, "setuptotp");

//assert totpSecret doesn't change after a wrong submit
assertEquals(totpSecret, totpPage.getTotpSecret());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public void testUpdateOTP() throws IOException {
// Dummy OTP code won't work when configure new OTP
loginConfigTotpPage.configure(DummyUserFederationProvider.HARDCODED_OTP);
Assertions.assertEquals("Invalid authenticator code.", loginConfigTotpPage.getInputCodeError());
events.clear();

// This will save the credential to the local DB
String totpSecret = loginConfigTotpPage.getTotpSecret();
Expand Down
Loading
0