mirror of
https://github.com/ansible-middleware/keycloak.git
synced 2026-11-24 01:44:00 +00:00
keycloak_userprofile: support required.scopes
Keycloak can require a user profile attribute only when one of the given client scopes is requested, but the module's argument spec only accepted required.roles and rejected required.scopes.
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user