【问题标题】:Authorization failure with AWS API GatewayAWS API Gateway 授权失败
【发布时间】:2016-11-30 04:23:24
【问题描述】:

我已将 AWS API Gateway 与 AWS Cognito 用户池集成。以下 curl 命令有效。

curl -X PUT -H "Authorization:<id token>" -d <json data> <https url>

但是,以下 Angularjs $http.put 授权失败。 AWS cloudwatch 日志显示“用户未经授权”

$http.defaults.headers.common['Authorization'] = token
$http.put('https://<url>', <json data> )
    .then(function (data, status, headers, config) {
        console.log('success')
    }, function (data, status, headers, config) {
        console.log('failure')
    });

授权令牌应该如何用$http.put设置?

【问题讨论】:

    标签: angularjs amazon-web-services curl aws-api-gateway


    【解决方案1】:

    我认为您想要做的是将请求的标头设置为$http.put(&lt;url&gt;, options)... 中的第二个参数。

    所以在你的情况下,你的代码应该是这样的:

    var options = {headers:  {
                            'Authorization': token,
                            'Content-Type': 'application/json'
                            }
                  };
    
    $http.put('https://<url>', <json data>, options);
    

    您可以查看documentation here 以了解有关调用$http.X 方法的不同方式的更多信息。

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2021-01-08
      • 1970-01-01
      • 2021-08-05
      • 2017-04-13
      • 1970-01-01
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多