- Newest
- Most votes
- Most comments
The "Invalid key=value pair (missing equal-sign) in Authorization header" error you're encountering is related to how the Authorization header is being formatted when making the API Gateway request. This is a common issue when working with API Gateway authentication.
Based on your workflow, there are a few potential issues:
-
Authorization Header Format: The error suggests there's an issue with the format of your Authorization header. When using a Bearer token, the format should be exactly
Authorization: Bearer xxxxxwith a space between "Bearer" and the token. Check if there might be any extra spaces, line breaks, or special characters in your token. -
Token Processing: Your workflow is attempting to clean the token by removing newlines and carriage returns, but there might still be some invisible characters or formatting issues. The error message indicates that the SHA-256 hash of your Authorization header doesn't match what's expected.
-
API Gateway Configuration: The API Gateway might be expecting a different authentication method. If it's configured to use AWS Signature Version 4 (SigV4) authentication rather than a simple Bearer token, you'll need to sign your request properly.
Here are some suggestions to fix the issue:
- Verify Token Format: Double-check that your token doesn't contain any unexpected characters. You might want to add additional cleaning:
TOKEN=$(echo "$TOKEN" | tr -d '\n' | tr -d '\r' | xargs)
- Modify the curl command: Try explicitly setting the Authorization header with quotes:
curl -s -X POST "${{ steps.get-endpoint.outputs.endpoint }}" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
-
Check API Gateway Requirements: If your API Gateway is configured to use AWS SigV4 authentication, you'll need to sign your request using the AWS credentials rather than just passing a Bearer token. In this case, you might need to use the AWS CLI or SDK to make the request instead of curl.
-
Debug the Token: Add a step to print out the exact Authorization header being sent (with sensitive parts redacted) to verify its format.
If you're certain that the API Gateway expects a Cognito JWT token as a Bearer token, then the issue is likely with how the token is being processed or formatted in your curl command. Make sure there are no extra characters or encoding issues with the token.
Sources
API Gateway - Missing Authentication Token | AWS re:Post
Troubleshoot Signature Version 4 signing for AWS API requests - AWS Identity and Access Management
Use InitiateAuth with an AWS SDK or CLI - Amazon Cognito
answered a year ago
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated a year ago
