-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure-keycloak.txt
86 lines (72 loc) · 2.95 KB
/
configure-keycloak.txt
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
keycloak_docker_container_name=keycloak8446
# run keycloak in docker, in daemon mode... make sure you set the `KEYCLOAK_ADMIN` and `KEYCLOAK_ADMIN_PWD` environment variables
docker run \
-d \
--name ${keycloak_docker_container_name} \
--user root \
-p 8446:8446 \
-v /data/docker/letsencrypt:/etc/letsencrypt \
-v /data/docker/keycloak/themes/mytheme:/opt/keycloak/themes/mytheme \
-e KEYCLOAK_ADMIN=${KEYCLOAK_ADMIN_USER} \
-e KEYCLOAK_ADMIN_PASSWORD=${KEYCLOAK_ADMIN_PWD} \
quay.io/keycloak/keycloak:23.0.1 start \
--https-certificate-file=/etc/letsencrypt/live/${WILDCARD_DNS}/fullchain.pem \
--https-certificate-key-file=/etc/letsencrypt/live/${WILDCARD_DNS}/privkey.pem \
--hostname=keycloak.${WILDCARD_DNS} \
--https-port=8446
function kcadm {
docker exec -it ${keycloak_docker_container_name} /opt/keycloak/bin/kcadm.sh $@;
}
kcadm config credentials \
--server ${KEYCLOAK_HOST_AND_PORT} \
--realm master \
--user ${KEYCLOAK_ADMIN_USER} \
--password ${KEYCLOAK_ADMIN_PWD}
kcadm create realms \
-s realm=${KEYCLOAK_REALM} \
-s enabled=true
kcadm create clients \
-r ${KEYCLOAK_REALM} \
-s clientId=${ZITI_BROWZER_CLIENT_ID} \
-s protocol=openid-connect \
-s 'redirectUris=["https://'${ZITI_BROWZER_VHOST}'/*","https://'${KEYCLOAK_BASE}:${TEST_PORT}'/*","http://localhost:8080/*"]' \
-s 'webOrigins=["https://'${ZITI_BROWZER_VHOST}'","https://'${KEYCLOAK_BASE}:${TEST_PORT}'","http://localhost:8080"]' \
-s 'directAccessGrantsEnabled=true'
CLIENT_SCOPE_ID=$(kcadm get clients -r ${KEYCLOAK_REALM} | jq -r '.[] | select(.clientId == "'${ZITI_BROWZER_CLIENT_ID}'") | .id')
kcadm update realms/${KEYCLOAK_REALM}/clients/${CLIENT_SCOPE_ID} --set fullScopeAllowed=false
kcadm create clients/${CLIENT_SCOPE_ID}/protocol-mappers/models \
-r ${KEYCLOAK_REALM} \
-s name=audience-mapping \
-s protocol=openid-connect \
-s protocolMapper=oidc-audience-mapper \
-s config.\"included.custom.audience\"="ctrl.${WILDCARD_DNS}" \
-s config.\"access.token.claim\"=\"true\" \
-s config.\"id.token.claim\"=\"false\"
NEW_USER_NAME=testuser
NEW_USER_PWD=testpwd
kcadm create users \
-r ${KEYCLOAK_REALM} \
-s username=${NEW_USER_NAME} \
-s enabled=true
kcadm set-password \
-r ${KEYCLOAK_REALM} \
--username ${NEW_USER_NAME} \
--new-password ${NEW_USER_PWD}
TEST_PORT=8080
# OPTIONAL: -- enable IdPs -- you MUST provide the client id and secret
kcadm create identity-provider/instances \
-r ${KEYCLOAK_REALM} \
-s alias=github-oidc \
-s providerId=github \
-s enabled=true \
-s 'config.useJwksUrl="true"' \
-s config.clientId=${ZITI_BROWZER_GITHUB_CLIENT} \
-s config.clientSecret=${ZITI_BROWZER_GITHUB_CLIENTSECRET}
kcadm create identity-provider/instances \
-r ${KEYCLOAK_REALM} \
-s alias=google-oidc \
-s providerId=google \
-s enabled=true \
-s 'config.useJwksUrl="true"' \
-s config.clientId=${ZITI_BROWZER_GOOGLE_CLIENT} \
-s config.clientSecret=${ZITI_BROWZER_GOOGLE_CLIENTSECRET}