AWS Cognito 授权 API 呼叫使用 Javascript

AWS Cognito Authorize API call Using Javascript

我有一个 API 由 AWS cognito 服务进行身份验证。我想用 ajax 来调用它。我为此使用了下面的代码。

  $.ajax({
                    url: 'https://XXXXXXXXX.execute-api.us-east-2.amazonaws.com/XXXXXXXX/setusername',
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    header :{'Authorization':result.getIdToken().getJwtToken()},
                    success: function (data, textStatus, xhr) {
                        console.log(data);
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        console.log('Error in Operation');
                    }
                });

但是当我执行它时它给了我以下错误。(注意:当我从 API 网关中删除 cognito Auth 时这个工作正常)

Console Error

and below is my integration response

试试这个库来签署对您的 API Lambda 方法的调用 https://github.com/mhart/aws4

或者您正在使用自定义身份验证?