Far*_*hti 3 authentication post web-services oauth postman
在使用 Postman 的 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)
Web服务调用生成令牌-
https://api-perf.myglobal.com/rest/oauth2/v1/token
邮政
client_id:abcd
client_secret:xyz
grant_type:client_credentials
每当调用任何未处理的端点方法或资源时,我都会遇到这种情况。我的设置是一个 API 网关,具有定义的资源(例如/myendpoint
)和为这些端点定义的方法(例如GET
)。
为了解决这个问题,我创建了一个仅返回 404 的 Node.js Lambda 函数。然后,我ANY
在端点的根添加了任意方法/
,并将其作为 Lambda 代理函数指向 ANY 方法。
然后我添加了一个代理资源,例如/{proxy}
——创建资源时可以单击一个复选框来告诉它进行代理。该资源上的方法ANY
指向相同的 Lambda 函数,部署 API,然后我就完成了。
现在,我得到了正确的错误,而不是身份验证持有者令牌错误HTTP 404
。
@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)
归档时间: |
|
查看次数: |
24752 次 |
最近记录: |