Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a custom attribute required field on keycloak registration form

I have the registration process working so that the custom attribute of "phone" is being stored when the user clicks register, if the user typed a phone number in that is. However, I would like it to be a required field and prevent registration from occurring if left blank. I have not found any keycloak documentation about how to do this.

like image 496
user1869407 Avatar asked Jun 29 '17 18:06

user1869407


1 Answers

You have to implement a SPI that extend the registration form. You can use standard FormAction as base. You will have to add you validation logic to validate() method. For instance:

String phoneNumber = formData.getFirst(FIELD_PHONE_NUMBER);
if (Validation.isBlank(phoneNumber) {
  errors.add(new FormMessage(FIELD_PHONE_NUMBER, MISSING_PHONE_NUMBER));
}
like image 199
Yeray Rodriguez Avatar answered Sep 26 '22 23:09

Yeray Rodriguez