Skip to content

Instantly share code, notes, and snippets.

@lukaszbudnik
Last active February 10, 2024 21:28
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lukaszbudnik/05425886bfb2fcca99f42da5c2b3ae54 to your computer and use it in GitHub Desktop.
Save lukaszbudnik/05425886bfb2fcca99f42da5c2b3ae54 to your computer and use it in GitHub Desktop.
youtube.com - Keycloak Multi-Tenant JavaScript Clients
# don't forget to update below variables to point to your Keycloak instance, main realm, and admin user
export KEYCLOAK_URL="http://localhost:8080"
export KEYCLOAK_MAIN_REALM=master
export KEYCLOAK_USER=lb
export KEYCLOAK_PASSWORD=***
# get the access token
access_token=$(curl --silent \
-d "client_id=admin-cli" \
-d "username=$KEYCLOAK_USER" \
-d "password=$KEYCLOAK_PASSWORD" \
-d "grant_type=password" \
"$KEYCLOAK_URL/auth/realms/$KEYCLOAK_MAIN_REALM/protocol/openid-connect/token" | jq -r '.access_token')
# create customer100 realm
curl -v -X POST -H "Authorization: bearer $access_token" -H "Content-Type: application/json" --data-binary @new_realm.json $KEYCLOAK_URL/auth/admin/realms
# check if realm created successfully
curl -H "Authorization: bearer $access_token" $KEYCLOAK_URL/auth/admin/realms/customer100 | jq
# create react client
curl -v -X POST -H "Authorization: bearer $access_token" -H "Content-Type: application/json" --data-binary @new_client.json $KEYCLOAK_URL/auth/admin/realms/customer100/clients
# check if client created successfully
curl -H "Authorization: bearer $access_token" $KEYCLOAK_URL/auth/admin/realms/customer100/clients?clientId=react | jq
{
"clientId": "react",
"rootUrl": "http://customer100.localtest.me:3000",
"enabled": true,
"redirectUris": [
"http://customer100.localtest.me:3000/*"
],
"webOrigins": [
"http://customer100.localtest.me:3000"
],
"publicClient": true,
"protocol": "openid-connect"
}
{
"id": "customer100",
"realm": "customer100",
"enabled": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment