1
+ #! /bin/bash
2
+
3
+ # Start Docker containers
4
+ CONFIG_FILE=./env/local.js docker compose -f docker-compose-with-keycloak.yml up -d --build
5
+ sleep 30
6
+
7
+ # Configure client credentials flow
8
+ KEYCLOAK_ACCESS_TOKEN=$( curl -X POST " http://localhost:8080/realms/master/protocol/openid-connect/token" -H " Content-Type: application/x-www-form-urlencoded" -d " client_id=admin-cli" -d " username=keycloak" -d " password=keycloak" -d " grant_type=password" | jq -r ' .access_token' )
9
+ curl -X POST " http://localhost:8080/admin/realms" -H " Authorization: Bearer $KEYCLOAK_ACCESS_TOKEN " -H " Content-Type: application/json" -d ' {"realm": "debugger-testing", "enabled": true}'
10
+ curl -X POST " http://localhost:8080/admin/realms/debugger-testing/client-scopes" -H " Authorization: Bearer $KEYCLOAK_ACCESS_TOKEN " -H " Content-Type: application/json" -d ' {"name": "client-credentials-scope", "protocol": "openid-connect", "attributes": {"display.on.consent.screen": "false", "include.in.token.scope": "true"}}'
11
+ curl -X POST " http://localhost:8080/admin/realms/debugger-testing/clients" -H " Authorization: Bearer $KEYCLOAK_ACCESS_TOKEN " -H " Content-Type: application/json" -d ' {"clientId": "client-credentials", "protocol": "openid-connect", "publicClient": false, "serviceAccountsEnabled": true, "authorizationServicesEnabled": false, "standardFlowEnabled": false, "directAccessGrantsEnabled": false, "clientAuthenticatorType": "client-secret"}'
12
+ KEYCLOAK_CLIENT_CREDENTIALS_CLIENT_ID=$( curl " http://localhost:8080/admin/realms/debugger-testing/clients?clientId=client-credentials" -H " Authorization: Bearer $KEYCLOAK_ACCESS_TOKEN " | jq -r ' .[0].id' )
13
+ KEYCLOAK_CLIENT_CREDENTIALS_CLIENT_CLIENTID=$( curl " http://localhost:8080/admin/realms/debugger-testing/clients?clientId=client-credentials" -H " Authorization: Bearer $KEYCLOAK_ACCESS_TOKEN " | jq -r ' .[0].clientId' )
14
+ KEYCLOAK_CLIENT_CREDENTIALS_CLIENT_SECRET=$( curl " http://localhost:8080/admin/realms/debugger-testing/clients?clientId=client-credentials" -H " Authorization: Bearer $KEYCLOAK_ACCESS_TOKEN " | jq -r ' .[0].secret' )
15
+ KEYCLOAK_CLIENT_CREDENTIALS_SCOPE_ID=$( curl " http://localhost:8080/admin/realms/debugger-testing/client-scopes" -H " Authorization: Bearer $KEYCLOAK_ACCESS_TOKEN " | jq -r ' .[] | select(.name=="client-credentials-scope") | .id' )
16
+ KEYCLOAK_CLIENT_CREDENTIALS_SCOPE_NAME=$( curl " http://localhost:8080/admin/realms/debugger-testing/client-scopes" -H " Authorization: Bearer $KEYCLOAK_ACCESS_TOKEN " | jq -r ' .[] | select(.name=="client-credentials-scope") | .name' )
17
+ curl -X PUT " http://localhost:8080/admin/realms/debugger-testing/clients/$KEYCLOAK_CLIENT_CREDENTIALS_CLIENT_ID /optional-client-scopes/$KEYCLOAK_CLIENT_CREDENTIALS_SCOPE_ID " -H " Authorization: Bearer $KEYCLOAK_ACCESS_TOKEN "
18
+
19
+ # Install dependencies
20
+ cd tests && npm install
21
+
22
+ # Test client credentials flow
23
+ DISCOVERY_ENDPOINT=" http://localhost:8080/realms/debugger-testing/.well-known/openid-configuration" \
24
+ CLIENT_ID=$KEYCLOAK_CLIENT_CREDENTIALS_CLIENT_CLIENTID \
25
+ CLIENT_SECRET=$KEYCLOAK_CLIENT_CREDENTIALS_CLIENT_SECRET \
26
+ SCOPE=$KEYCLOAK_CLIENT_CREDENTIALS_SCOPE_NAME \
27
+ node oauth2_client_credentials.js
0 commit comments