keycloak_clienttemplate – Allows administration of Keycloak client templates via Keycloak API

New in version 2.5.

Synopsis

  • This module allows the administration of Keycloak client templates via the Keycloak REST API. It requires access to the REST API via OpenID Connect; the user connecting and the client being used must have the requisite access rights. In a default Keycloak installation, admin-cli and an admin user would work, as would a separate client definition with the scope tailored to your needs and a user having the expected roles.

  • The names of module options are snake_cased versions of the camelCase ones found in the Keycloak API and its documentation at http://www.keycloak.org/docs-api/3.3/rest-api/

  • The Keycloak API does not always enforce for only sensible settings to be used – you can set SAML-specific settings on an OpenID Connect client for instance and vice versa. Be careful. If you do not specify a setting, usually a sensible default is chosen.

Parameters

Parameter Choices/Defaults Comments
attributes
-
A dict of further attributes for this client template. This can contain various configuration settings, though in the default installation of Keycloak as of 3.4, none are documented or known, so this is usually empty.
auth_client_id
string / required
Default:
"admin-cli"
OpenID Connect client_id to authenticate to the API with.
auth_client_secret
string
Client Secret to use in conjunction with auth_client_id (if required).
auth_keycloak_url
string / required
URL to the Keycloak instance.

aliases: url
auth_password
string / required
Password to authenticate for API access with.

aliases: password
auth_realm
string / required
Keycloak realm name to authenticate to for API access.
auth_username
string / required
Username to authenticate for API access with.

aliases: username
description
-
Description of the client template in Keycloak
full_scope_allowed
boolean
    Choices:
  • no
  • yes
Is the "Full Scope Allowed" feature set for this client template or not. This is 'fullScopeAllowed' in the Keycloak REST API.
id
-
Id of client template to be worked on. This is usually a UUID.
name
-
Name of the client template
protocol
-
    Choices:
  • openid-connect
  • saml
Type of client template (either openid-connect or saml.
protocol_mappers
-
a list of dicts defining protocol mappers for this client template. This is 'protocolMappers' in the Keycloak REST API.
config
-
Dict specifying the configuration options for the protocol mapper; the contents differ depending on the value of protocolMapper and are not documented other than by the source of the mappers and its parent class(es). An example is given below. It is easiest to obtain valid config values by dumping an already-existing protocol mapper configuration through check-mode in the "existing" field.
consentRequired
-
Specifies whether a user needs to provide consent to a client for this mapper to be active.
consentText
-
The human-readable name of the consent the user is presented to accept.
id
-
Usually a UUID specifying the internal ID of this protocol mapper instance.
name
-
The name of this protocol mapper.
protocol
-
    Choices:
  • openid-connect
  • saml
is either 'openid-connect' or 'saml', this specifies for which protocol this protocol mapper is active.
protocolMapper
-
The Keycloak-internal name of the type of this protocol-mapper. While an exhaustive list is impossible to provide since this may be extended through SPIs by the user of Keycloak, by default Keycloak as of 3.4 ships with at least
docker-v2-allow-all-mapper
oidc-address-mapper
oidc-full-name-mapper
oidc-group-membership-mapper
oidc-hardcoded-claim-mapper
oidc-hardcoded-role-mapper
oidc-role-name-mapper
oidc-script-based-protocol-mapper
oidc-sha256-pairwise-sub-mapper
oidc-usermodel-attribute-mapper
oidc-usermodel-client-role-mapper
oidc-usermodel-property-mapper
oidc-usermodel-realm-role-mapper
oidc-usersessionmodel-note-mapper
saml-group-membership-mapper
saml-hardcode-attribute-mapper
saml-hardcode-role-mapper
saml-role-list-mapper
saml-role-name-mapper
saml-user-attribute-mapper
saml-user-property-mapper
saml-user-session-note-mapper
An exhaustive list of available mappers on your installation can be obtained on the admin console by going to Server Info -> Providers and looking under 'protocol-mapper'.
realm
-
Realm this client template is found in.
state
-
    Choices:
  • present ←
  • absent
State of the client template
On present, the client template will be created (or updated if it exists already).
On absent, the client template will be removed if it exists
validate_certs
boolean
    Choices:
  • no
  • yes ←
Verify TLS certificates (do not disable this in production).

Notes

Note

  • The Keycloak REST API defines further fields (namely bearerOnly, consentRequired, standardFlowEnabled, implicitFlowEnabled, directAccessGrantsEnabled, serviceAccountsEnabled, publicClient, and frontchannelLogout) which, while available with keycloak_client, do not have any effect on Keycloak client-templates and are discarded if supplied with an API request changing client-templates. As such, they are not available through this module.

Examples

- name: Create or update Keycloak client template (minimal)
  local_action:
    module: keycloak_clienttemplate
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
    realm: master
    name: this_is_a_test

- name: delete Keycloak client template
  local_action:
    module: keycloak_clienttemplate
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
    realm: master
    state: absent
    name: test01

- name: Create or update Keycloak client template (with a protocol mapper)
  local_action:
    module: keycloak_clienttemplate
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
    realm: master
    name: this_is_a_test
    protocol_mappers:
      - config:
          access.token.claim: True
          claim.name: "family_name"
          id.token.claim: True
          jsonType.label: String
          user.attribute: lastName
          userinfo.token.claim: True
        consentRequired: True
        consentText: "${familyName}"
        name: family name
        protocol: openid-connect
        protocolMapper: oidc-usermodel-property-mapper
    full_scope_allowed: false
    id: bce6f5e9-d7d3-4955-817e-c5b7f8d65b3f

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
end_state
dictionary
always
client template representation of client template after module execution (sample is truncated)

Sample:
{'description': 'test01', 'fullScopeAllowed': False, 'id': '9c3712ab-decd-481e-954f-76da7b006e5f', 'name': 'test01', 'protocol': 'saml'}
existing
dictionary
always
client template representation of existing client template (sample is truncated)

Sample:
{'description': 'test01', 'fullScopeAllowed': False, 'id': '9c3712ab-decd-481e-954f-76da7b006e5f', 'name': 'test01', 'protocol': 'saml'}
msg
string
always
Message as to what action was taken

Sample:
Client template testclient has been updated
proposed
dictionary
always
client template representation of proposed changes to client template

Sample:
{'name': 'test01'}


Status

Authors

  • Eike Frost (@eikef)

Hint

If you notice any issues in this documentation, you can edit this document to improve it.