AWS API Gateway + Cognito用户池授权程序+ Lambda - 我需要设置哪些HTTP标头和权限?

tho*_*ers 7 restkit amazon-iam amazon-cognito aws-lambda

我在AWS上通过HTTP标头(没有AWS API Gateway SDK)获取Cognito用户池的API授权时遇到问题.

我的设置:

在AWS上:

  • 在AWS Lambda上实现的REST API(通过无服务器框架部署),
  • 使用类型LAMBDA_PROXY通过API网关公开(无手动映射)
  • 通过提供的"Cognito用户池授权程序"对API网关进行授权(无"AWS_IAM"选项,无自定义编码授权程序)
  • 通过Postman测试API

在iOS客户端上

  • 通过AWS Cognito注册/登录(从AWS Mobile Hub生成的演示Xcode项目复制的SDK和UI)
  • 通过RestKit访问REST API ,而不是使用AWSAPIGateway SDK

工作原理:

API方法通过无服务器正确部署.

我可以通过Postman呼叫公众(不设置使用用户池).

对于私有API方法,我可以看到Cognito用户池授权API网关管理控制台设置,包括"身份令牌源"设置为method.request.header.Authorization(默认值)所描述的在这里

在iOS上,我可以正确注册并以用户身份登录.我可以转储AWS证书的详细信息到控制台,显示AccessKey,SecretKeySessionKey.

在iOS上,我可以通过RestKit查询公共API.

当我尝试通过Postman调用私有API方法时,我收到了身体的HTTP错误401 {"message": "Unauthorized"}.(预计没有设置任何授权.)

什么失败:

为了测试授权,在邮递员中,我试过了

结果始终是401错误.

我需要设置什么作为HTTP标头,以便授权对私有API的调用?"授权"应该有效 - 也许我缺少一些角色权限?

如何更好地调试权限/授权流程?

tho*_*ers 2

这是获取会话的方法:

\n\n
AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:AWSCognitoUserPoolsSignInProvi\xe2\x80\x8c\xe2\x80\x8bderKey]; \nAWSCognitoIdentityUser *user = [pool currentUser]; \nAWSTask<AWSCognitoIdentityUserSession *> *task = [user getSession];\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后,task.result.idToken.tokenString可以设置为“Authorization”标头,并且它可以工作。

\n\n

感谢彼得的提示!

\n