Paclet to connect to Keycloak APIs using Wolfram Language
First, install and load the necessary paclets:
PacletInstall["WTC/Utilities"]
PacletDirectoryLoad["<path/to/your/paclet/folder>"];
Get["KeycloakLink`"];
Open a connection to your Keycloak server:
conn = OpenKeycloakConnection[
"https://localhost:8443", "master",
Authentication -> <|
"grant_type" -> "password",
"auth_details" -> <|
"username" -> "******",
"password" -> "******",
"client_id" -> "******",
"client_secret" -> "******"
|>,
"scope" -> "openid roles profile"
|>
]
Retrieve various properties of the connection:
conn["Properties"]
conn["ID"]
conn["Requests"]
conn["Authentication"]
List all realms:
KeycloakExecute[conn, "ListRealm"]
Create a new realm:
KeycloakExecute[conn, "CreateRealm", "Body" -> ToJSON[<|"realm" -> "test1234", "enabled" -> True|>]]
Get client scope for a specific realm:
KeycloakExecute[conn, "GetClientScope", "DynamicPath" -> <|"realm" -> "test1234"|>]
Execute a command with token refresh:
KeycloakExecuteWithRefresh[conn, "GetClientScope", "DynamicPath" -> <|"realm" -> "test1234"|>]
Delete a realm:
KeycloakExecuteWithRefresh[conn, "DeleteRealm", "DynamicPath" -> <|"realm" -> "test1234"|>]
Verify JWT Token:
KeycloakLink`Common`ParseJWTToken[conn["TokenDetails"]["access_token"], "VerifySignature" -> True, "Issuer" -> "https://localhost"]