授权标头中不是有效的键=值对(缺少等号)

Far*_*hti 3 authentication post web-services oauth postman

在使用 Postman 的 API 时,我收到此错误。

API详细信息:

网址:

https://account-perf.myglobal.com/v1/users/00uk0khprrME7gZOU0h7/credentials/change_password

标题:

内容类型:application/json
授权:Bearer n7mbkw74jsubd7rauhptdnre

类型:

邮政

身体:

{"password":"Baddy125@","token":"eyJhbGci...."}
Run Code Online (Sandbox Code Playgroud)

编辑1:

Web服务调用生成令牌-

网址-

https://api-perf.myglobal.com/rest/oauth2/v1/token

类型-

邮政

身体-

client_id:abcd
client_secret:xyz
grant_type:client_credentials

Mat*_*t H 7

每当调用任何未处理的端点方法或资源时,我都会遇到这种情况。我的设置是一个 API 网关,具有定义的资源(例如/myendpoint)和为这些端点定义的方法(例如GET)。

为了解决这个问题,我创建了一个仅返回 404 的 Node.js Lambda 函数。然后,我ANY在端点的根添加了任意方法/,并将其作为 Lambda 代理函数指向 ANY 方法。

然后我添加了一个代理资源,例如/{proxy}——创建资源时可以单击一个复选框来告诉它进行代理。该资源上的方法ANY指向相同的 Lambda 函数,部署 API,然后我就完成了。

现在,我得到了正确的错误,而不是身份验证持有者令牌错误HTTP 404


sta*_*ley 5

@Matt H - 这是个好主意,这给了我另一个灵感。

假设 API 中的所有其他路径均已明确指定,我创建了一个默认路径 /{proxy+} ,它将返回 http 404,消息资源未找到。我没有使用 lambda,而是创建了一个模拟响应,因此让 Lambda 返回响应甚至不需要产生任何成本。

我通过开放 API 规范创建了我的 API。这就是我的 YAML 实施方式

  /{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"
Run Code Online (Sandbox Code Playgroud)

Serverless 还能够指定内联模拟响应。下面是一个示例:

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"}'
Run Code Online (Sandbox Code Playgroud)

无服务器文档:https ://www.serverless.com/framework/docs/providers/aws/events/apigateway/#custom-response-templates