【问题标题】:Automatic request signing with API Gateway REST API and Amplify使用 API Gateway REST API 和 Amplify 自动签署请求
【发布时间】:2019-08-04 10:20:52
【问题描述】:

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'

但在 Angular 中这不起作用,因为 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};
       }
     }
   ]
 }

【问题讨论】:

    标签: aws-api-gateway aws-amplify


    【解决方案1】:

    已解决请求 url 有错字,它必须是 /items/:test 其中 test 是 dynamo 中的分区名称,也是

     headers: {
               Authorization: token
             },
    

    不需要

    https://github.com/aws-amplify/amplify-js/issues/2810#issuecomment-470213459

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-25
      • 2017-07-10
      • 2016-05-10
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 2018-11-12
      相关资源
      最近更新 更多