此https://aws-amplify.github.io/docs/js/api#signing-request-with-iam说,AWS Amplify提供了自动签名请求的功能。.与受Cognito限制的API网关REST请求是否一样?
auth.currentSession().then(token => {
console.log('>>>>', token.getIdToken().getJwtToken());
authToken = token.getIdToken().getJwtToken();
const myInit = { // OPTIONAL
headers: {
Authorization: authToken
},
response: true,
};
api.get(apiName, path, myInit).then(response => {
// Add your code here
console.log(response);
}).catch(error => {
console.log(error.response);
});
}
);
但是我得到了授权标头requires 'Credential' parameter. Authorization header requires 'Signature'
但是在有角度的情况下,这无法正常工作,因为Auth.currentSession()
无法编译
endpoints: [
{
name: 'test',
endpoint: 'https://xyz.execute-api.us-west-2.amazonaws.com/test',
custom_header: async () => {
// Alternatively, with Cognito User Pools use this:
return {Authorization: (await Auth.currentSession()).idToken.jwtToken};
}
}
]
}
答案 0 :(得分:0)
已解决,其中包含请求网址的错字,必须为/items/:test
,其中test是发电机中的分区名称,也是
headers: {
Authorization: token
},
不是必需的 :
https://github.com/aws-amplify/amplify-js/issues/2810#issuecomment-470213459