我正在尝试创建一个应用程序,用户可以在其中注册,然后根据他们的角色访问某些api资源。
用户被移到用户池中的组中,每个组都有一个自定义IAM角色。
我使用了扩展CLI工具来创建身份验证、api网关和lambda函数。这是在放大中设置的API
? Please select from one of the below mentioned services: REST
? Please select the REST API you would want to update standardApi
? What would you like to do Update path
? Please select the path you would want to edit /std
? Provide a path (e.g., /book/{isbn}): /std
? Choose a Lambda source Use a Lambda function already added in the current Ampl
ify project
? Choose the Lambda function to invoke by this path standardFunction
? Restrict API access Yes
? Restrict access by? Individual Groups
? Select groups: standard
? What kind of access do you want for standard users? create, read, update, dele
te
Successfully updated resource当在控制台中签入时,将按预期的方式创建资源。
问题是,当我试图调用API时,我收到了一个MissingAuthenticationTokenException。
这就是我的电话
const apiName = 'standardApi';
const path = '/std';
const myInit = {
headers: {},
response: false
};
API.get(apiName, path, myInit)
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error.response);
});我的理解是,扩容sdk应该使用正确的身份验证值自动填充请求标头。
如果我尝试手动传递访问令牌,
headers: {
Authorization: (await Auth.currentSession()).getIdToken().getJwtToken()
},我收到了IncompleteSignatureException的留言
Authorization header requires 'Credential' parameter. Authorization header requires 'Signature' parameter. Authorization header requires 'SignedHeaders' parameter. Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header.正在尝试
headers: {
Authorization: `Bearer ${(await Auth.currentSession()).getIdToken().getJwtToken()}
},结果在IncompleteSignatureException中没有消息。
其他文章建议,如果我从控制台中的api中删除auth并重新部署,端点可能不会被正确指定,端点将按预期的方式命中。此外,如果我使用认知用户池创建一个自定义授权程序,则端点在登录时将被正确命中,并且传递一个承载令牌。
只是IAM的案子不起作用。
检查ID令牌显示正在传递正确的用户名、组和角色。
"cognito:groups": Array [ "standard" ]
"cognito:preferred_role": "arn:aws:iam::************:role/region-*_*********-standardGroupRole"
"cognito:roles": Array [ "arn:aws:iam::************:role/region-*_*********-standardGroupRole"]
"cognito:username": "0a******-****-****-****-************"放大器配置步骤是用自动生成的aws-导出文件完成的,该文件包含用户池、身份池和客户端应用程序的正确条目。
发布于 2021-01-14 19:43:47
我知道这可能有点晚,但我只想做你想做的同样的事情。
这是我必须做的,让它发挥作用:
specified).
通过这样做,我可以在浏览器的开发人员控制台中看到请求已被签名,并且拥有API Gateway所做的IAM授权验证所需的所有标头。
我希望这片云对某些人有用,因为我花了很多时间才弄清楚它。
你好,安德烈斯·拉诺斯
https://stackoverflow.com/questions/63127943
复制相似问题