-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: initialize keycloak in local docker-compose infrastructure
Signed-off-by: Pat Losoponkul <[email protected]>
- Loading branch information
Pat Losoponkul
committed
Oct 3, 2023
1 parent
a23b7a5
commit 53edab9
Showing
3 changed files
with
84 additions
and
2,385 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -u | ||
|
||
KEYCLOAK_BASE_URL=$KEYCLOAK_BASE_URL | ||
KEYCLOAK_ADMIN_USER=$KEYCLOAK_ADMIN_USER | ||
KEYCLOAK_ADMIN_PASSWORD=$KEYCLOAK_ADMIN_PASSWORD | ||
REALM_NAME=$REALM_NAME | ||
PRISM_AGENT_CLIENT_SECRET=$PRISM_AGENT_CLIENT_SECRET | ||
|
||
function get_admin_token() { | ||
local response=$( | ||
curl --request POST "$KEYCLOAK_BASE_URL/realms/master/protocol/openid-connect/token" \ | ||
--fail -s \ | ||
-d "grant_type=password" \ | ||
-d "client_id=admin-cli" \ | ||
-d "username=$KEYCLOAK_ADMIN_USER" \ | ||
-d "password=$KEYCLOAK_ADMIN_PASSWORD" | ||
) | ||
local access_token=$(echo $response | jq -r '.access_token') | ||
echo $access_token | ||
} | ||
|
||
function create_realm() { | ||
local access_token=$1 | ||
|
||
curl --request POST "$KEYCLOAK_BASE_URL/admin/realms" \ | ||
--fail -s \ | ||
-H "Authorization: Bearer $access_token" \ | ||
-H "Content-Type: application/json" \ | ||
--data-raw "{ | ||
\"realm\": \"$REALM_NAME\", | ||
\"enabled\": true | ||
}" | ||
} | ||
|
||
function create_prism_agent_client() { | ||
local access_token=$1 | ||
|
||
local response=$( | ||
curl --request POST "$KEYCLOAK_BASE_URL/admin/realms/$REALM_NAME/clients" \ | ||
--fail -s \ | ||
-H "Authorization: Bearer $access_token" \ | ||
-H "Content-Type: application/json" \ | ||
--data-raw "{ | ||
\"id\": \"prism-agent\", | ||
\"directAccessGrantsEnabled\": true, | ||
\"authorizationServicesEnabled\": true, | ||
\"serviceAccountsEnabled\": true, | ||
\"secret\": \"$PRISM_AGENT_CLIENT_SECRET\" | ||
}" | ||
) | ||
echo $response | ||
} | ||
|
||
echo "Getting admin access token ..." | ||
ADMIN_ACCESS_TOKEN=$(get_admin_token) | ||
|
||
echo "Creating a new test realm ..." | ||
create_realm $ADMIN_ACCESS_TOKEN | ||
|
||
echo "Creating a new prism-agent client ..." | ||
create_prism_agent_client $ADMIN_ACCESS_TOKEN |
Oops, something went wrong.