-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsetup_keycloak.sh
executable file
·56 lines (49 loc) · 1.54 KB
/
setup_keycloak.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
export $(grep -v '^#' .env | xargs)
echo -n "Getting admin access token..."
ADMIN_TOKEN=$(curl -ks -X POST \
"$KEYCLOAK_URL/auth/realms/master/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=$KEYCLOAK_ADMIN_LOGIN" \
-d "password=$KEYCLOAK_ADMIN_PASSWORD" \
-d 'grant_type=password' \
-d 'client_id=admin-cli' | jq -r '.access_token')
if [ $ADMIN_TOKEN == "null" ]; then
echo -e "${RED} \u2717 Could not get admin token ${NC}"
exit 1
else
echo -e "${GREEN} \xE2\x9C\x94 ${NC}"
fi
echo -n "Setting access token lifespan to 1 hour..."
response=$(curl -iks -X PUT "$KEYCLOAK_URL/auth/admin/realms/master" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '
{
"accessTokenLifespan": 3600
}' | grep HTTP | awk '{print $2}')
if [ $response == "204" ]; then
echo -e "${GREEN} \u2713 ${NC}"
else
echo -e "${RED} \u2717 ${NC}"
fi
echo -n "Creating $KEYCLOAK_DASHBOARDS_CLIENT_ID client"
response=$(curl -kis -X POST "$KEYCLOAK_URL/auth/admin/realms/master/clients" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '
{
"clientId": "'$KEYCLOAK_DASHBOARDS_CLIENT_ID'",
"rootUrl": "https://172.17.0.1:5601",
"redirectUris": ["https://172.17.0.1:5601/*"],
"publicClient": false,
"secret": "'$KEYCLOAK_DASHBOARDS_CLIENT_SECRET'"
}'| grep HTTP | awk '{print $2}')
if [ $response == "201" ]; then
echo -e "${GREEN} \u2713 ${NC}"
else
echo -e "${RED} \u2717 ${NC}"
fi