英文:
How to add user attributes to registration form in Keycloak?
问题
I've created a new realm (out of the box and using user account for login/registration) in Keycloak and enabled the user profile, added a new attribute - shop.
The user attribute.
Because this attribute is required, I want it to be in the default registration form.
Is this possible to do?
It will be nice to have the user attributes in the JWT token as well.
英文:
I've created a new realm (out of the box and using user account for login/registration) in Keycloak and enabled the user profile, added a new attribute - shop
Because this attribute is required, I want it to be in the default registration form
Is this possible to do?
It will be nice to have the user attributes in the JWT token as well
答案1
得分: 3
您可以通过添加自定义主题(可以通过覆盖主题来实现,但他们不建议覆盖主题)向注册表单添加字段。
在主题文件夹中添加一个自定义主题。
自定义./themes/custom-theme/login/register.ftl
文件以添加以下自定义字段:
(请按照链接进行操作)
<div class="${properties.kcFormGroupClass!}">
<div class="${properties.kcLabelWrapperClass!}">
<label for="user.attributes.dob" class="${properties.kcLabelClass!}">
出生日期</label>
</div>
<div class="${properties.kcInputWrapperClass!}">
<input type="date" class="${properties.kcInputClass!}"
id="user.attributes.dob" name="user.attributes.dob"
value="${(register.formData['user.attributes.dob']!'')}"/>
</div>
</div>
然后在成功注册后,出生日期将作为用户属性添加。
英文:
You can add a field to the registration form by adding a custom theme (You might do it by overriding the main theme, but they don't recommend overriding the main theme).
Add a custom theme in the themes folder.
Customize your ./themes/custom-theme/login/register.ftl
file to add a custom field like the below:
(Please follow the link)
<div class="${properties.kcFormGroupClass!}">
<div class="${properties.kcLabelWrapperClass!}">
<label for="user.attributes.dob" class="${properties.kcLabelClass!}">
Date of birth</label>
</div>
<div class="${properties.kcInputWrapperClass!}">
<input type="date" class="${properties.kcInputClass!}"
id="user.attributes.dob" name="user.attributes.dob"
value="${(register.formData['user.attributes.dob']!'')}"/>
</div>
</div>
Then the dob will be added as user attributes after a successful registration.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论