【问题标题】:how to add authentication to aws api gateway call in NodeJS如何在 NodeJS 中向 aws api 网关调用添加身份验证
【发布时间】:2017-11-05 00:05:50
【问题描述】:

我使用以下选项从节点调用 AWS APi Gateway:

var post_options = {
        host: 'myurl.execute-api.us-west-2.amazonaws.com',
        port: '443'
        path: '/staging/api',
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Content-Length': Buffer.byteLength(post_data)
        }
    };

调用方式如下:

http.post(post_options, post_data, function(res){
            res.setEncoding('utf8');
            res.on('data', function(chunk) {
                console.log(chunk);
            });
        });

我得到的回复是:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Bad request.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: Yl1rUhK7Bmaq57ckHvK1E32tqNqDs4GC078yek3_23_RMefXUGJAdA==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>
name: undefined
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Bad request.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: nJ3dotCRum8XudR6v0PinqzDjjPCX3N5TmoM2fNQSJK9BLn8jJEWqg==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

我想,我收到“错误请求”是因为我没有将任何身份验证信息传递给我的呼叫。 添加此类身份验证信息的正确语法是什么?

【问题讨论】:

  • 您在 API 端点上配置了什么身份验证?如果您没有配置任何内容,则没有任何内容,并且您的错误是其他内容。
  • 我的同事配置了该部分。我会和他核实一下。
  • 如果它与身份验证相关,您将不会得到 400(错误请求)。你会得到 401(未经授权)或 403(禁止)。请检查您的请求是否正确。

标签: node.js amazon-web-services aws-api-gateway


【解决方案1】:

API Gateway 不支持分块编码,这是您尝试在后端使用的吗?如果通过 API Gateway 返回的响应标头表明我们应该使用分块编码,则可能存在问题。

无论如何,您都不应该收到此错误,但我想确定有关您的 API/后端的更多细节。

【讨论】:

    猜你喜欢
    • 2018-01-21
    • 2022-01-01
    • 2017-11-04
    • 1970-01-01
    • 1970-01-01
    • 2020-03-12
    • 2019-03-25
    • 2020-04-02
    • 2015-04-12
    相关资源
    最近更新 更多