[英]Getting 401 Unauthorized from AWS Cognito + API Gateway when accessing from Postman or cURL
我正在尝试使用 AWS Cognito 提供的令牌通过 Postman 或 cURL 访问 URL,但我没有这样做。
我使用下面的 CloudFormation 模板创建了一个带有 JWT 身份验证的 API。
登录后,我可以使用返回的 URL 和 access_token 访问 lambda function。 这按预期工作:
http://<api_url>/?access_token=<token>
但是当我尝试使用 header 中的 access_token 从 Postman 或 cURL 访问它时,它输出 401。我期望获得访问权限。
$ curl -v -X GET <url> -H "Authorization: <token>"
{"message":"Unauthorized"}
我试过什么:
Authorization: Bearer <token>
,但仍然得到 401。HTTP/2 401
date: Thu, 03 Mar 2022 20:12:58 GMT
content-type: application/json
content-length: 26
www-authenticate: Bearer
apigw-requestid: ObIjqhmPIAMEJtA=
* Connection #0 to host <url> left intact
{"message":"Unauthorized"}
JWT Authorizer 配置为:
JWTAuthorizer:
Type: AWS::ApiGatewayV2::Authorizer
Properties:
ApiId: !Ref MyAPI
AuthorizerType: JWT
IdentitySource:
- '$request.querystring.access_token'
JwtConfiguration:
Audience:
- !Ref AppClient
Issuer: !Sub https://cognito-idp.${AWS::Region}.amazonaws.com/${UserPool}
Name: test-jwt-authorizer
IdentitySource 必须是“$request.header.Authorization”才能从 header.Authorization 中读取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.