android - 在 Android 中放大 Auth,无法访问管理查询 API
问题描述
我正在使用 Amplify Auth 类别,其中包含一个 Admin Queries Api 但无法访问该 api。
在 Postman 中,我使用 GET 方法测试端点:
https://xxxxxxxxxxxx.execute-api.eu-west-2.amazonaws.com/dev/getUser/?username=jan
(我在 admin 组中有一个名为 jan 的 cognito 用户)。我包含一个 Authorization 标头,其中包含用户 id 令牌作为值。(在 api 网关控制台中使用它来测试 api 网关授权器时,id 令牌值起作用)。Postman 返回 401 未授权状态。Cloudwatch 中没有显示任何内容。
在 Api Gateway 控制台中,当测试 api 的任何资源操作时,我使用以下设置:
method: GET,
path {proxy}: getUser,
query strings {proxy}: username=jan,
headers {proxy}: Authorization:id token
结果表明成功完成执行,方法完成,状态为:500但返回“消息”:“无法读取未定义的属性'声明'”
lambda 执行显示在 Cloudwatch 中。
感谢任何帮助。
谢谢
解决方案
500 错误的原因是因为 Api 网关没有正确转发 Cognito 身份验证的用户。
Lambda 可能在AdminQueries
处失败req.apiGateway.event.requestContext.authorizer.claims["cognito:groups"]
,它设置为检查所有路由。
如何使用 API Gateway、Lambda、Cognito 和 AWS Amplify 在 AWS 上创建经过身份验证的 REST API帮助我进行了设置。
推荐阅读
- python - 从自然语言问题中提取实体
- javascript - 如何在 map() 内部查询并从 connection.query 中获取结果?
- javascript - 无法在 Chrome 93 Cypress 8.4.1 中输入“数字”输入字段
- python - 在保存字体样式的同时读取 python 中的 doc/docx 内容
- mongodb - mongodb 中使用 $or 运算符的条件
- python - django AttributeError: 'tuple' 对象没有属性 'rsplit'
- android - 如何使用 ConstraintLayout Flow 更改元素的位置?
- vue.js - 如何通过类型 /en 或 /fr 设置路由
- unity3d - 如何在 Unity 中使用 Lerp Dash 运动
- javascript - 为什么在这种情况下 TypeScript 会推断出错误的类型?