@@ -214,19 +214,26 @@ jobs:
214214
215215 # Create a properly URL-encoded request
216216 echo "Creating token exchange request..."
217+ curl_data=$(cat << 'EOF'
218+ client_id=$IDENTITY_FEDERATION_CLIENT_ID&\
219+ subject_token=$OIDC_TOKEN&\
220+ subject_token_type=urn:ietf:params:oauth:token-type:jwt&\
221+ grant_type=urn:ietf:params:oauth:grant-type:token-exchange&\
222+ scope=sql
223+ EOF
224+ )
225+
226+ # Substitute environment variables in the curl data
227+ curl_data=$(eval echo "$curl_data")
217228
218229 # Print request details (except the token)
219230 echo "Request URL: https://$DATABRICKS_HOST_FOR_TF/oidc/v1/token"
220- echo "Request data: client_id=$IDENTITY_FEDERATION_CLIENT_ID& subject_token=REDACTED&subject_token_type=urn:ietf:params:oauth:token-type:jwt&grant_type=urn:ietf:params:oauth:grant-type:token-exchange&scope=sql "
231+ echo "Request data: $(echo "$curl_data" | sed 's/subject_token=.*&/ subject_token=REDACTED&/') "
221232
222233 # Make the request with detailed info
223234 echo "Sending request..."
224235 response=$(curl -v -s -X POST "https://$DATABRICKS_HOST_FOR_TF/oidc/v1/token" \
225- --data-urlencode "client_id=$IDENTITY_FEDERATION_CLIENT_ID" \
226- --data-urlencode "subject_token=$OIDC_TOKEN" \
227- --data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:jwt" \
228- --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
229- --data-urlencode "scope=sql" \
236+ --data-raw "$curl_data" \
230237 -H "Content-Type: application/x-www-form-urlencoded" \
231238 -H "Accept: application/json" \
232239 2>&1)
@@ -239,6 +246,13 @@ jobs:
239246 status_code=$(echo "$response" | grep -o "< HTTP/[0-9.]* [0-9]*" | grep -o "[0-9]*$" || echo "unknown")
240247 echo "HTTP Status Code: $status_code"
241248
249+ # Try to extract and pretty-print the JSON response body if present
250+ response_body=$(echo "$response" | sed -n -e '/^{/,/^}/p' || echo "")
251+ if [ ! -z "$response_body" ]; then
252+ echo "Response body (formatted):"
253+ echo "$response_body" | python3 -m json.tool || echo "$response_body"
254+ fi
255+
242256 # Don't fail the workflow if curl fails
243257 exit 0
244258
@@ -315,6 +329,18 @@ jobs:
315329 print(f"Expected: {audience}")
316330 print(f"Actual: {claims.get('aud')}")
317331
332+ # Enable more verbose HTTP debugging
333+ import http.client as http_client
334+ http_client.HTTPConnection.debuglevel = 1
335+
336+ # Log requests library debug info
337+ import logging
338+ logging.basicConfig()
339+ logging.getLogger().setLevel(logging.DEBUG)
340+ requests_log = logging.getLogger("requests.packages.urllib3")
341+ requests_log.setLevel(logging.DEBUG)
342+ requests_log.propagate = True
343+
318344 response = requests.post(url, data=data, headers=headers)
319345
320346 print(f"Status code: {response.status_code}")
0 commit comments