Created
June 6, 2019 19:33
-
-
Save njgibbon/383a164465380f38b1b9c9dca2f9d4a6 to your computer and use it in GitHub Desktop.
Keycloak admin API example in python based on https://gist.github.com/paoloantinori/84c644efb44002493835
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
keycloak_url = 'http://localhost:8080/' | |
admin_token_endpoint = 'auth/realms/master/protocol/openid-connect/token' | |
realms_endpoint = 'auth/admin/realms' | |
bearer_token = '' | |
url='' | |
print("get the admin bearer token") | |
data = dict ( | |
username='admin', | |
password='admin', | |
grant_type='password', | |
client_id='admin-cli', | |
) | |
headers = { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Accept': 'application/json' | |
} | |
url=keycloak_url+admin_token_endpoint | |
response = requests.post(url, data=data, headers=headers) | |
print(response) | |
print("get realms list") | |
response = response.json() | |
bearer_token = 'Bearer ' + response.get('access_token') | |
headers = { | |
'Accept': 'application/json', | |
'Authorization': bearer_token | |
} | |
url=keycloak_url+realms_endpoint | |
response = requests.get(url, headers=headers) | |
print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment