首页 > 解决方案 > 在 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 中。

感谢任何帮助。

谢谢

标签: androidauthorizationaws-api-gatewayamplify

解决方案


500 错误的原因是因为 Api 网关没有正确转发 Cognito 身份验证的用户。

Lambda 可能在AdminQueries处失败req.apiGateway.event.requestContext.authorizer.claims["cognito:groups"],它设置为检查所有路由。

如何使用 API Gateway、Lambda、Cognito 和 AWS Amplify 在 AWS 上创建经过身份验证的 REST API帮助我进行了设置。


推荐阅读