Merge pull request #448 from mangin/userprofile-required-scopes

keycloak_userprofile: support required.scopes
This commit is contained in:
Ranabir Chakraborty
2026-11-03 12:06:17 +05:30
committed by GitHub
3 changed files with 58 additions and 1 deletions
@@ -107,3 +107,22 @@ config_unmanaged_attributes_admin_view:
kc_user_profile_config:
- unmanagedAttributePolicy: ADMIN_VIEW
attributes: "{{ attributes_default }}"
attributes_required_by_scope:
- name: requiredByScope
displayName: requiredByScope
required:
roles:
- user
scopes:
- profile
permissions:
view:
- admin
- user
edit: []
multivalued: false
config_required_by_scope:
kc_user_profile_config:
- attributes: "{{ attributes_default + attributes_required_by_scope }}"
@@ -185,3 +185,30 @@
- result.end_state.providerId == "declarative-user-profile"
- result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider"
- result.msg.startswith("Userprofile declarative-user-profile changed:")
- name: Require an attribute only for a client scope
middleware_automation.keycloak.keycloak_userprofile:
state: present
parent_id: "{{ ephemeral_realm }}"
config: "{{ config_required_by_scope }}"
diff: true
register: result
- name: Assert the attribute is required for the scope
ansible.builtin.assert:
that:
- result is changed
- (result.end_state.config['kc.user.profile.config'][0].attributes | selectattr('name', 'equalto', 'requiredByScope') | first).required.scopes == ['profile']
- name: Require an attribute only for a client scope (idempotency)
middleware_automation.keycloak.keycloak_userprofile:
state: present
parent_id: "{{ ephemeral_realm }}"
config: "{{ config_required_by_scope }}"
register: result
- name: Assert the scoped requirement is in sync
ansible.builtin.assert:
that:
- result is not changed
- result.msg == "Userprofile declarative-user-profile was in sync"
+12 -1
View File
@@ -257,6 +257,13 @@ options:
default:
- user
scopes:
description:
- The client scopes for which this attribute is required.
- If not set, the attribute is required regardless of the requested scopes.
type: list
elements: str
selector:
description:
- Selector when the attribute should be added.
@@ -583,7 +590,11 @@ def main():
),
"multivalued": dict(type="bool", default=False),
"required": dict(
type="dict", options={"roles": dict(type="list", elements="str", default=["user"])}
type="dict",
options={
"roles": dict(type="list", elements="str", default=["user"]),
"scopes": dict(type="list", elements="str"),
},
),
"selector": dict(type="dict", options={"scopes": dict(type="list", elements="str")}),
},