Skip to content

Commit eb9c10b

Browse files
committed
fix: improve token diagnostics and error messages
1 parent b2dd3a2 commit eb9c10b

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

.github/workflows/test_cloudflare_purge.yml

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,36 @@ jobs:
2323
ZONE_ID=$(echo "${{ secrets.CLOUDFLARE_ZONE }}" | tr -d '[:space:]')
2424
AUTH_TOKEN=$(echo "${{ secrets.CLOUDFLARE_AUTH_KEY }}" | tr -d '[:space:]')
2525
26+
echo "=== Token Diagnostics ==="
2627
echo "Zone ID length: ${#ZONE_ID}"
28+
echo "Zone ID: ${ZONE_ID:0:8}...${ZONE_ID: -8}"
2729
echo "Token length: ${#AUTH_TOKEN}"
28-
echo "Token preview: ${AUTH_TOKEN:0:10}...${AUTH_TOKEN: -5}"
2930
31+
# Show token preview more safely
32+
if [ ${#AUTH_TOKEN} -ge 15 ]; then
33+
TOKEN_START="${AUTH_TOKEN:0:8}"
34+
TOKEN_END="${AUTH_TOKEN: -8}"
35+
echo "Token preview: ${TOKEN_START}...${TOKEN_END}"
36+
else
37+
echo "⚠️ WARNING: Token seems too short (${#AUTH_TOKEN} chars). API tokens are typically 40+ characters."
38+
echo "Token preview: ${AUTH_TOKEN:0:4}...${AUTH_TOKEN: -4}"
39+
fi
40+
41+
# Check token type hints
42+
if [ ${#AUTH_TOKEN} -lt 45 ]; then
43+
echo ""
44+
echo "⚠️ Token length suggests it might be:"
45+
echo " - A Global API Key (~37 chars) - requires email + key authentication"
46+
echo " - An incomplete/truncated API Token"
47+
echo ""
48+
echo "For API Tokens:"
49+
echo " - Should be 40+ characters long"
50+
echo " - Created in: Cloudflare Dashboard → My Profile → API Tokens"
51+
echo " - Needs 'Zone.Cache Purge' permission"
52+
echo " - Used with: Authorization: Bearer <token>"
53+
fi
54+
55+
echo ""
3056
echo "Testing token by fetching zone info..."
3157
VERIFY_RESPONSE=$(curl -s -w "\n%{http_code}" -X GET \
3258
"https://api.cloudflare.com/client/v4/zones/${ZONE_ID}" \
@@ -41,10 +67,31 @@ jobs:
4167
echo "❌ Token verification failed!"
4268
echo "$VERIFY_BODY" | jq '.' || echo "$VERIFY_BODY"
4369
echo ""
44-
echo "Common issues:"
45-
echo "1. Token may be invalid or expired"
46-
echo "2. Token may not have 'Zone.Read' permission"
47-
echo "3. Zone ID may be incorrect"
70+
echo "=== Troubleshooting ==="
71+
ERROR_CODE=$(echo "$VERIFY_BODY" | jq -r '.errors[0].code' 2>/dev/null || echo "")
72+
if [ "$ERROR_CODE" = "9109" ]; then
73+
echo "Error 9109: Invalid access token"
74+
echo ""
75+
echo "This usually means:"
76+
echo "1. The token is not a valid API Token"
77+
echo "2. The token might be a Global API Key (requires different auth method)"
78+
echo "3. The token was incorrectly copied (check for extra spaces/newlines)"
79+
echo "4. The token is expired or revoked"
80+
echo ""
81+
echo "To create a proper API Token:"
82+
echo "1. Go to: https://dash.cloudflare.com/profile/api-tokens"
83+
echo "2. Click 'Create Token'"
84+
echo "3. Use 'Edit zone DNS' template or create custom token with:"
85+
echo " - Zone: Zone Settings:Read"
86+
echo " - Zone: Zone:Read"
87+
echo " - Zone: Cache Purge:Edit"
88+
echo "4. Copy the ENTIRE token (it's long!)"
89+
else
90+
echo "Common issues:"
91+
echo "1. Token may be invalid or expired"
92+
echo "2. Token may not have 'Zone.Read' permission"
93+
echo "3. Zone ID may be incorrect"
94+
fi
4895
exit 1
4996
else
5097
ZONE_NAME=$(echo "$VERIFY_BODY" | jq -r '.result.name' 2>/dev/null || echo "unknown")

0 commit comments

Comments
 (0)