Skip to content

Instantly share code, notes, and snippets.

@glennswest
Created August 26, 2017 13:11
Show Gist options
  • Save glennswest/50ad4aeecc91e5d1b1b246d4075cde62 to your computer and use it in GitHub Desktop.
Save glennswest/50ad4aeecc91e5d1b1b246d4075cde62 to your computer and use it in GitHub Desktop.
Create Keycloak Client Registration Using Ansible URL Module
---
- hosts: localhost
vars:
description: "auth users"
create_data:
clientId: "openshift"
name: "OpenShift"
description: "OpenShift Console Authentication"
enabled: true
protocol: "openid-connect"
clientAuthenticatorType: "client-secret"
directAccessGrantsEnabled: true
redirectUris: ["https://gsw1v11.southeastasia.cloudapp.azure.com:8443"]
webOrigins: []
publicClient: false
consentRequired: false
frontchannelLogout: false
standardFlowEnabled: true
tasks:
- name: Login to SSO
uri:
url: https://login.52.160.91.126.nip.io/auth/realms/cloud/protocol/openid-connect/token
method: POST
body: "grant_type=pass&client_id=admin-cli&username=mgmtuser&password=mgmtpass"
return_content: yes
status_code: 200
validate_certs: no
register: login
- debug: var=login.json.access_token
- name: Login to SSO
uri:
url: https://login.52.160.91.126.nip.io/auth/realms/cloud/clients-registrations/default
method: POST
headers:
"Authorization": "bearer {{login.json.access_token}}"
"Content-Type": "application/json"
body: "{{ create_data | to_json }}"
return_content: yes
status_code: 201
validate_certs: no
register: create
- debug: var=create.json.secret
@roicostas
Copy link

"grant_type" should be "password" instead of "pass", at least with Keycloak 3.4.3

You may also add client_secret parameter for confidential clients

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment