Skip to content

Commit d83e1ac

Browse files
committed
Fix Cloudflare Access IDP lookup and JSON body issues
- Handle null .result from identity_providers API with // [] fallback - Also match by name (case-insensitive 'google') in case the type differs - Log the IDP API response summary for debugging - Only include allowed_idps + auto_redirect_to_identity when IDP is found - Use a dummy trailing field (tags) to avoid JSON trailing comma issues
1 parent 02e580f commit d83e1ac

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

.github/workflows/publish.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,21 @@ jobs:
110110
| jq -r --arg domain "$DOMAIN" '.result[] | select(.domain == $domain) | .id')
111111
112112
# Find the Google identity provider ID (skip the OTP provider)
113-
GOOGLE_IDP=$(curl -s -X GET \
113+
IDP_RESPONSE=$(curl -s -X GET \
114114
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/access/identity_providers" \
115115
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
116-
-H "Content-Type: application/json" \
117-
| jq -r '.result[] | select(.type == "google" or .type == "google-apps") | .id' | head -1)
116+
-H "Content-Type: application/json")
117+
echo "Identity providers response: $(echo "$IDP_RESPONSE" | jq -c '{success: .success, result_count: (.result | length), types: [.result[]?.type]}')"
118118
119-
if [ -z "$GOOGLE_IDP" ]; then
120-
echo "Warning: Could not find Google identity provider."
121-
ALLOWED_IDPS=""
122-
else
119+
GOOGLE_IDP=$(echo "$IDP_RESPONSE" \
120+
| jq -r '(.result // [])[] | select(.type == "google" or .type == "google-apps" or (.name | test("google";"i"))) | .id' | head -1)
121+
122+
if [ -n "$GOOGLE_IDP" ]; then
123123
echo "Found Google identity provider: $GOOGLE_IDP"
124-
ALLOWED_IDPS="\"allowed_idps\": [\"$GOOGLE_IDP\"],"
124+
IDP_EXTRA="\"allowed_idps\": [\"$GOOGLE_IDP\"], \"auto_redirect_to_identity\": true,"
125+
else
126+
echo "Warning: Could not find Google identity provider. Login screen will show all providers."
127+
IDP_EXTRA=""
125128
fi
126129
127130
if [ -n "$EXISTING_APP" ]; then
@@ -135,8 +138,8 @@ jobs:
135138
\"domain\": \"$DOMAIN\",
136139
\"type\": \"self_hosted\",
137140
\"session_duration\": \"24h\",
138-
$ALLOWED_IDPS
139-
\"auto_redirect_to_identity\": true
141+
$IDP_EXTRA
142+
\"tags\": []
140143
}"
141144
echo "Updated Access application."
142145
exit 0
@@ -152,8 +155,8 @@ jobs:
152155
\"domain\": \"$DOMAIN\",
153156
\"type\": \"self_hosted\",
154157
\"session_duration\": \"24h\",
155-
$ALLOWED_IDPS
156-
\"auto_redirect_to_identity\": true
158+
$IDP_EXTRA
159+
\"tags\": []
157160
}")
158161
159162
APP_ID=$(echo "$APP_RESPONSE" | jq -r '.result.id')

0 commit comments

Comments
 (0)