not a valid key=value pair (missing equal-sign) in Authorization header

14,609

Solution 1

I had this whenever any unhandled endpoint method or resource was called. My setup is an API Gateway with defined resources (e.g. /myendpoint) and defined methods for those endpoints (e.g. GET).

To fix it, I created a Node.js Lambda function that just returned a 404. Then I added any ANY method at the root of the endpoints / and pointed it as a Lambda proxy function to the ANY methods.

Then I added a proxy resource, e.g. /{proxy} -- there's a checkbox you can click when creating a resource to tell it to proxy. An ANY method on that resource pointing to the same Lambda function, deploy the API, and I'm done.

Now instead of the auth bearer token error, I get a proper HTTP 404 error.

Solution 2

@Matt H - That's pretty good idea this gave me an inspiration of another one.

Assuming all of the other paths within the API are explicitly specified, I created a default path /{proxy+} which would return a http 404, message resource not found. Instead of using lambda, I was able to create a mock response, so there isn't even any cost incurred for getting Lambda to return the response.

I created my APIs via Open API spec. This is how my YAML for the implementation would like

  /{proxy+}:
    x-amazon-apigateway-any-method:
      responses:
        404:
          description: "404 response"
          content: {}
      x-amazon-apigateway-integration:
        responses:
          404:
            statusCode: "404"
            responseTemplates:
              application/json: "{\"message\":\"resource not available\"}"
        requestTemplates:
          application/json: "{\"statusCode\": 404}"
        passthroughBehavior: "when_no_templates"
        type: "mock"

Serverless also has the ability to specify inline mock response. Below can be a sample:

functions:
  default:
    handler: handler.default
    events:
      - http:
          path: hello
          cors: true
          method: get
          integration: mock
          request:
            template:
              application/json: '{"statusCode": 404}'
          response:
            template: $input.path('$')
            statusCodes:
              404:
                pattern: '' #default method
                template:
                  application/json: '{"statusCode": 404, "message":"resource not found"}'

serverless doc: https://www.serverless.com/framework/docs/providers/aws/events/apigateway/#custom-response-templates

Solution 3

Analyze and validate the request path, in case the request is incorrect this error is thrown at API Gateway. I stepped on the same error, when corrected the request parameters it worked well.

Let me know.

Share:
14,609
Farrukh Chishti
Author by

Farrukh Chishti

Looking for jobs as Java or Hybris developer. Please contact me at- [email protected]

Updated on June 05, 2022

Comments