Extending business logic when account is updated in v14.0.0?

I want to change the logic during the update of an account

Some details

I have a custom attribute to hold the phoneNumber of the user

On registration, a FormAction validates the phoneNumber and sends a code to the phone number

I will implement a new endpoint/page for entering the code received by SMS that will set another custom attribute phoneNumberVerified

What I’d like to do is to check the phoneNumber and send a SMS if it changed during the account update

At the moment, the phoneNumber is displayed and the user can change it (this is because I am using a custom attribute)

However, I do not see how I can change the logic to validate the phone number, to set the phoneNumberVerified to false and to send a SMS to the new phoneNumber

I’ve seen Adjust user account update processing but there is not a lot of details (and I would prefer to stay inside keycloak if possible, not creating a 3rd party app)

I’d like to know if the new UserProfile feature is usable in 14.0.0 and if yes if it can cover my use case ?

Otherwise, is it possible to use the EventListener SPI in order to “intercept” the account update ?

at least to know if the phoneNUmber has been changed and, if yes, set phoneNumberVerified to false and re-send a SMS (I know I won’t be able to validate the phone number with this SPI)

Thanks for your time,

You can listen for UPDATE_PROFILE in your EventListenerProvider


I don’t believe the user profile validation features will fulfill your requirement in v14.

Thanks @xgp for your answer, I’ll go with that solution

Another question : is the userprofile feature supposed to cover the use case (i.e custom logic when editing the account) in future versions ?

I think the new user profile functionality will allow you to perform validation, but not to implement custom logic when editing occurs. However, I am not an expert on this new functionality, so it’s worth looking at the docs to see if I am missing something.


Thanks again @xgp

performing validation will be enough (i.e validating that phoneNumber is correct and that it is not used by another user)

I’ll continue to use the eventlistener to set the phoneNumberVerified to false and to send a SMS to the new phoneNumber