How to disable First and Last name in the User Account Service?

Hi all
How can I disable the field First and Last name in the account page?

Is there any SPI available?

Thanks

Hi @softshipper,

sorry there doesn’t seem to be a solution for this.
There is a design proposal out there but it’s far from done https://github.com/keycloak/keycloak-community/blob/master/design/user-profile.md

You can take a look at org.keycloak.services.resources.account.AccountFormService and the processAccountUpdate method which updates your account. There is a validation method in there the checks the first and last name.

You could clone the repo and change these things and make your own custom build if you really need this fast.

Have fun and hope this helps somewhat

Thanks for answer @zonaut.

Is it maybe better to create own user account page? The page will provide users to change their email and password. What is your recommendation?

Thanks

It all depends on the time you’re willing to spend and the requirements of your project.

If your application is in the context of an enterprise than you probably wan’t to leave these fields enabled because it’s an enterprise, you need an account so you fill it in.
If your application is something public and you need to attract users than you want a fast registration process and don’t ask too many questions upfront.
These are probably the main use cases but there will be a lot more.

In both situations you will need the first and last name at some point because we need those things to get more personal with our users. Personalized emails, messages and so on.

My use case for example is an SPA which will be the main thing users will spend their time on after registration. I have my own profile page in that app which also contains some personal details like first and last name. These details are saved in my own DB. But when changes happen on email, first or last name I push them back to Keycloak from my own API so Keycloak has the actual information.
I will probably hide certain parts of the account page in my custom theme as I don’t want users to change things there and will change certain things from my own app as this gives a more needless integration of things.

At the end of the day you are free to do what you want and have access to the source code of the whole thing so that’s a plus. But again, this all depends on your needs.

Some or most enterprises will probably have their own build because they require changes and fixes faster than the default release period. They also have a couple of persons in charge to keep up to date with latest bugs and fixes and especially CVE’s so that they can react fast if necessary.

What I would like to achieve is the same as you have done.

I have my own profile page in that app which also contains some personal details like first and last name. These details are saved in my own DB. But when changes happen on email, first or last name I push them back to Keycloak from my own API so Keycloak has the actual information.

That is exactly, what I need. Which API do you use to push back to Keycloak and how do you do it? Where can I find the API’s?

My scenario:
On the registration page, users will be asked only for email and password. After that, users will spend their time on the SPA and they should have the opportunity to change their email and password. In addition, I would like to add some fields to user model. First and last name will stay initial, because I do not need the personal information from users and that is also the reason, why I would like to delete them from UI.

Thanks

You can find information about the Keycloak admin API on https://www.keycloak.org/docs-api/9.0/rest-api/index.html

If you do a search on Keycloak admin client you can find several examples on how to use it, there is even a test helper for it.

1 Like

Thanks a lot @zonaut. I will try to implement it and will post the implementation.

Thanks a lot again.

@zonaut one more question, is AccountFormService a SPI or just a usable class?

The AccountFormService is a mixed bag of everyhting but acts primarily like a controller. But it’s not an SPI which was probably what you wanted to know.
Have fun with your implementation.

1 Like