Skip to content

Commit

Permalink
Update update-kc.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
JavaDeveloper456788 authored Dec 17, 2024
1 parent 9700c3f commit a177652
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Keycloak/update-kc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ KC_USERNAME=$3
KC_REALM_ID=$4
SCRIPTS_PATH=$5
KC_TOKEN_URL=$6
TKN=""
REFRESH_TOKEN=""
TKN_FILE="/tmp/token.txt"



curl -o roles.sh $SCRIPTS_PATH/grad-roles.dat
Expand All @@ -23,6 +23,7 @@ response=$(curl -s -v -w POST \
"$KC_TOKEN_URL/$KC_REALM_ID/protocol/openid-connect/token")
TKN=$(echo "$response" | jq -r '.access_token')
REFRESH_TOKEN=$(echo "$response" | jq -r '.refresh_token')
echo "$TKN" > "$TKN_FILE"
echo "initial refresh token $REFRESH_TOKEN"


Expand All @@ -35,6 +36,7 @@ while true; do
TKN=$(echo "$response" | jq -r '.access_token')
echo "refresh+ $response \n"
REFRESH_TOKEN=$(echo "$response" | jq -r '.refresh_token')
echo "$TKN" > "$TKN_FILE"
sleep 30
done &
REFRESH_PID=$!
Expand All @@ -45,7 +47,7 @@ echo -e "CREATE Roles \n"
while read line
do
result=$(curl -s -w "%{http_code}" -X POST "$KC_BASE_URL/$KC_REALM_ID/roles" \
--header "Authorization: Bearer $TKN" \
--header "Authorization: Bearer "$(cat "$TKN_FILE")" " \
--header "Content-Type: application/json" \
--data-raw "$line")
echo -e " Response : $result\n"
Expand All @@ -63,7 +65,7 @@ do
fi

result=$(curl -s -w "%{http_code}" -X POST "$KC_BASE_URL/$KC_REALM_ID/client-scopes" \
--header "Authorization: Bearer $TKN" \
--header "Authorization: Bearer "$(cat "$TKN_FILE")" \
--header "Content-Type: application/json" \
--data-raw "{\"id\": \"$CLIENT_SCOPE_TRIMMED\", \"name\": \"$CLIENT_SCOPE\", \"protocol\": \"openid-connect\", \"attributes\": { \"include.in.token.scope\": \"true\", \"display.on.consent.screen\": \"false\"}}")
echo -e " Response : $result\n"
Expand All @@ -76,7 +78,7 @@ echo -e "CREATE Clients \n"
jq -c '.[]' clients.sh | while read -r client; do
result=$(curl -s -w "%{http_code}" -X POST "$KC_BASE_URL/$KC_REALM_ID/clients" \
--header "Authorization: Bearer $TKN" \
--header "Authorization: Bearer "$(cat "$TKN_FILE")" \
--header "Content-Type: application/json" \
--data-raw "$client")
echo -e " Response : $result\n"
Expand All @@ -85,15 +87,15 @@ jq -c '.[]' clients.sh | while read -r client; do
CLIENT_UUID=$(curl -s -X GET "$KC_BASE_URL/$KC_REALM_ID/clients" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TKN" \
-H "Authorization: Bearer "$(cat "$TKN_FILE")" \
| jq '.[] | select(.clientId=="'"$clientId"'")' | jq -r '.id')
echo "$default_scopes" | while read -r scope; do
echo "$CLIENT_UUID"
echo "$scope"
#PUT /{realm}/clients/{id}/default-client-scopes/{clientScopeId}
result=$(curl -s -w "%{http_code}" -X PUT "$KC_BASE_URL/$KC_REALM_ID/clients/$CLIENT_UUID/default-client-scopes/$scope" \
--header "Authorization: Bearer $TKN" \
--header "Authorization: Bearer "$(cat "$TKN_FILE")" \
--header "Content-Type: application/json" \
)
echo -e " Response : $result\n"
Expand Down

0 comments on commit a177652

Please sign in to comment.