mesutpiskin / keycloak-2fa-email-authenticator

🔒 Keycloak Authentication Provider implementation to get a two factor authentication with a OTP/code/token send via Email (through SMTP)
https://medium.com/@mesutpiskin/two-factor-authentication-via-email-in-keycloak-custom-auth-spi-935bbb3952a8
Apache License 2.0
164 stars 91 forks source link

Support for KC 25.0.2 #45

Open daniel-tedra opened 3 months ago

daniel-tedra commented 3 months ago

Everything seems to work but the last step where the plugin must show the OTP form. [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-836) Uncaught server error: java.lang.NoSuchMethodError: 'javax.ws.rs.core.Response org.keycloak.forms.login.LoginFormsProvider.createForm(java.lang.String)' at com.mesutpiskin.keycloak.auth.email.EmailAuthenticatorForm.challenge(EmailAuthenticatorForm.java:52) at com.mesutpiskin.keycloak.auth.email.EmailAuthenticatorForm.authenticate(EmailAuthenticatorForm.java:40) at org.keycloak.authentication.DefaultAuthenticationFlow.processSingleFlowExecutionModel(DefaultAuthenticationFlow.java:442) at org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:246) at org.keycloak.authentication.DefaultAuthenticationFlow.processSingleFlowExecutionModel(DefaultAuthenticationFlow.java:377) at org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:246) at org.keycloak.authentication.DefaultAuthenticationFlow.processSingleFlowExecutionModel(DefaultAuthenticationFlow.java:377) at org.keycloak.authentication.DefaultAuthenticationFlow.continueAuthenticationAfterSuccessfulAction(DefaultAuthenticationFlow.java:178) at org.keycloak.authentication.DefaultAuthenticationFlow.processAction(DefaultAuthenticationFlow.java:154) at org.keycloak.authentication.AuthenticationProcessor.authenticationAction(AuthenticationProcessor.java:1031) at org.keycloak.services.resources.LoginActionsService.processFlow(LoginActionsService.java:376) at org.keycloak.services.resources.LoginActionsService.processAuthentication(LoginActionsService.java:347) at org.keycloak.services.resources.LoginActionsService.authenticate(LoginActionsService.java:339) at org.keycloak.services.resources.LoginActionsService.authenticateForm(LoginActionsService.java:405) at org.keycloak.services.resources.LoginActionsService$quarkusrestinvoker$authenticateForm_13d428b70e62601585246c086a52f40868a3208e.invoke(Unknown Source) at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29) at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141) at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147) at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:582) at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538) at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29) at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:840)

vimalmahi commented 2 months ago

@daniel-tedra -- If you're building the app from latest source, you have to upgrade the lombok version in the pom file.

From <lombok.version>1.18.22</lombok.version> to <lombok.version>1.18.34</lombok.version>

Also, if you see the error javax.ws.rs.core.Response. This is deprecated now & the latest code is now using jakarta.xml.ws.Response

Once done, do mvn package from project root location and you can find the jar file in the /target folder. Replace the old jar with new one in the keycloak /providers folder and run the following to add the new provider. kc build kc start-dev

daniel-tedra commented 2 months ago

Hi I'm not a developer and I don't have a developer environment set to build, I just wanted a pre-built binary version with support for KC 25.02.

mesutpiskin commented 2 months ago

KC 25 support codes merged

kominoshja commented 2 months ago

@mesutpiskin I've verified the latest code builds correctly, but you might want to release a new package so folks don't download the wrong version

leobury commented 2 months ago

@kominoshja @mesutpiskin Hey ! I can't build the last version without editing the code on my side. I got some errors about EmailConstants and log.. Its the cas for you ?

[ERROR] /[...]keycloak-2fa-email-authenticator/src/main/java/com/mesutpiskin/keycloak/auth/email/EmailAuthenticatorForm.java:[158,13] cannot find symbol
[ERROR]   symbol:   variable log
[ERROR]   location: class com.mesutpiskin.keycloak.auth.email.EmailAuthenticatorForm

[ERROR] /[...]keycloak-2fa-email-authenticator/src/main/java/com/mesutpiskin/keycloak/auth/email/EmailAuthenticatorFormFactory.java:[57,58] non-static variable CODE_LENGTH cannot be referenced from a static context
[ERROR] /[...]keycloak-2fa-email-authenticator/src/main/java/com/mesutpiskin/keycloak/auth/email/EmailAuthenticatorFormFactory.java:[59,90] non-static variable DEFAULT_LENGTH cannot be referenced from a static context
[ERROR] /[...]keycloak-2fa-email-authenticator/src/main/java/com/mesutpiskin/keycloak/auth/email/EmailAuthenticatorFormFactory.java:[60,58] non-static variable CODE_TTL cannot be referenced from a static context
[ERROR] /[...]keycloak-2fa-email-authenticator/src/main/java/com/mesutpiskin/keycloak/auth/email/EmailAuthenticatorFormFactory.java:[62,54] non-static variable DEFAULT_TTL cannot be referenced from a static context
kominoshja commented 2 months ago

Not really, in my case, i had pulled the code, installed jdk17 and maven, and simply ran mvn package

leobury commented 2 months ago

Ok that's why, i'm with jdk23...

dedo1911 commented 1 month ago

KC 25 support codes merged

Thanks! Are you able to provide up to date build on Github Releases?