Skip to content

Commit f6ceb22

Browse files
committed
Fix token parsing issue
1 parent ac3b967 commit f6ceb22

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -369,21 +369,35 @@ jobs:
369369
exit 1
370370
fi
371371
372-
TOKEN=$(kubectl -n keycloak run curl-client --rm -i --restart=Never \
373-
--image=curlimages/curl:latest \
374-
--command -- \
375-
curl -s -X POST "http://keycloak.keycloak.svc.cluster.local:8080/realms/${REALM}/protocol/openid-connect/token" \
376-
-d "client_id=${CLIENT_ID}" \
377-
-d "username=${USER}" \
378-
-d "password=${PASSWORD}" \
379-
-d "grant_type=password" \
380-
-d "client_secret=${CLIENT_SECRET}" | jq -r .access_token)
381-
382-
if [ -z "$TOKEN" ]; then
372+
RAW=$(kubectl -n keycloak run curl-client \
373+
--image=curlimages/curl:latest \
374+
--restart=Never --rm -i \
375+
--command -- \
376+
curl -s -X POST "http://keycloak.keycloak.svc.cluster.local:8080/realms/${REALM}/protocol/openid-connect/token" \
377+
-d "client_id=${CLIENT_ID}" \
378+
-d "username=${USER}" \
379+
-d "password=${PASSWORD}" \
380+
-d "grant_type=password" \
381+
-d "client_secret=${CLIENT_SECRET}")
382+
383+
# Validate JSON before parsing
384+
if ! echo "$RAW" | jq . >/dev/null 2>&1; then
385+
echo "Token endpoint did not return valid JSON:"
386+
echo "$RAW"
387+
exit 1
388+
fi
389+
390+
# Extract the access token
391+
TOKEN=$(echo "$RAW" | jq -r .access_token)
392+
393+
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
383394
echo "Failed to fetch access token"
395+
echo "$RAW"
384396
exit 1
385397
fi
386398
399+
echo "Access token retrieved (length: ${#TOKEN})"
400+
387401
echo "Creating Kubernetes Secret with token..."
388402
kubectl -n ${NS} delete secret oauth-token --ignore-not-found
389403
kubectl -n ${NS} create secret generic oauth-token \

0 commit comments

Comments
 (0)