Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I correctly register a custom FormAction in Keycloak?

Tags:

keycloak

Keycloak 1.9.1-Final

I've implemented the following custom FormActionFactory.

public class RegistrationFormActionFactory implements FormActionFactory{

    public static final String PROVIDER_ID = "rc-registration-profile-action";

    @Override    
    public FormAction create(KeycloakSession session){
        return new RegistrationFormAction();
    }

    @Override
    public String getDisplayType(){
        return "RC Profile Validation";
    }
 ...

And the associated FormAction modeled after org.keycloak.authentication.forms.RegistrationProfile

public class RegistrationFormAction implements FormAction{
...

in META-INF/services of the jar I have a file: org.keycloak.authentication.FormActionFactory

containing only the following text:

com.realcomp.keycloak.RegistrationFormActionFactory

Within the Keycloak admin pages, I have made a copy of the Registration authentication flow and named it Copy of Registration. When adding an execution to my new flow I see my custom "RC Profile Validation" FormAction on the drop-down list of available providers. When selected, I get the following exception in the Keycloak server logs:

14:31:00,264 ERROR [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-54) RESTEASY002005: Failed executing POST /admin/realms/master/authentication/flows/Copy of registration registration form/executions/execution: org.jboss.resteasy.spi.BadRequestException: No authentication provider found for id: rc-registration-profile-action
at org.keycloak.services.resources.admin.AuthenticationManagementResource.addExecution(AuthenticationManagementResource.java:394)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
(omitted...)

Interesting side note: If I change the PROVIDER_ID in my FormActionFactory to "registration-profile-action" everything works as expected. However, this PROVIDER_ID is used by the RegistrationProfile class and feels wrong.

I increased logging verbosity and it appears my FormAction is being loaded:

17:07:20,659 DEBUG [org.keycloak.services] (ServerService Thread Pool -- 50) Loaded SPI form-action (providers = [registration-profile-action, rc-registration-profile-action, registration-recaptcha-action, registration-password-action, registration-user-creation])

I've likely missed some configuration step. Any ideas on what I did wrong here?

like image 517
Kyle Renfro Avatar asked Dec 20 '25 22:12

Kyle Renfro


1 Answers

This is a bug that came on version 1.9.x.

An issue ticket has already been created, you can follow it here:

https://issues.jboss.org/browse/KEYCLOAK-2842

like image 121
Leonardo Nunes Avatar answered Dec 23 '25 15:12

Leonardo Nunes