-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinitKeycloak.sh
More file actions
executable file
·97 lines (85 loc) · 2.15 KB
/
Copy pathinitKeycloak.sh
File metadata and controls
executable file
·97 lines (85 loc) · 2.15 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
set -e
function help
{
echo '
Usage initKeycloak.sh OPTIONS
add client to the master realm
Options:
-r, --realm-import Path to the realm import file
-s, --server Keycloak server URL
-a, --admin-name Keycloak Admin username
-p, --admin-pass Keycloak Admin password
--help Help Screen
'
}
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-r|--realm-import)
REALM_IMPORT_PATH="$2"
shift
shift
;;
-s|--server)
KEYCLOAK_SERVER="$2"
shift
shift
;;
-n|--name)
TENANT_NAME="$2"
shift
shift
;;
-a|--admin-name)
KEYCLOAK_ADMIN_NAME="$2"
shift
shift
;;
-p|--admin-pass)
KEYCLOAK_ADMIN_PASS="$2"
shift
shift
;;
--help)
help
exit
;;
--default)
DEFAULT=YES
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [[ "x${REALM_IMPORT_PATH}" = "x" ]]; then
REALM_IMPORT_PATH=./tenantSelectorApp/tenantSelectorAppClient.json
fi
if [[ "x${KEYCLOAK_SERVER}" = "x" ]]; then
KEYCLOAK_SERVER=http://localhost:8090/auth
fi
if [[ "x${KEYCLOAK_ADMIN_NAME}" = "x" ]]; then
KEYCLOAK_ADMIN_NAME=admin
fi
if [[ "x${KEYCLOAK_ADMIN_PASS}" = "x" ]]; then
KEYCLOAK_ADMIN_PASS=admin
fi
REGEX_TENANT_NAME=$(echo $TENANT_NAME| sed -e 's/\//\\\//g')
export REALM=$(cat ${REALM_IMPORT_PATH} )
export authResponse=$(curl -k -X POST "${KEYCLOAK_SERVER}/realms/master/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=${KEYCLOAK_ADMIN_NAME}" \
-d "password=${KEYCLOAK_ADMIN_PASS}" \
-d 'grant_type=password' \
-d 'client_id=admin-cli' )
access_token=$(echo $authResponse | awk -F"," '{print $1}' | awk -F":" '{print $2}' | sed s/\"//g | tr -d ' ')
#echo $access_token
curl -k -X POST "${KEYCLOAK_SERVER}/admin/realms/master/partialImport" -d "${REALM}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $access_token"