我想使用 HTTP 基本身份验证来密码保护可编程短信的状态回调端点。在来自 Twilio 的初始请求(没有授权 header )中,我发回状态代码 401,并将 WWW-Authenticate header 设置为“Basicrealm='somerealm'”。但是,我没有收到来自 Twilio 的以下带有授权 header 的请求。
引用:https://www.twilio.com/docs/usage/security#http-authentication
//发送带有状态回调的短信
const details = await client.messages
.create({
body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
from: 'TEST',
to: '......',
statusCallback: `https://user123:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="88f8e9fbfbb9babbc8eee7e7a6ebe7e5" rel="noreferrer noopener nofollow">[email protected]</a>/status`
})
//日志中的 Lambda 响应 header
Method response headers: {WWW-Authenticate=Basic realm='Validate twilio request', Content-Type=application/xml}
注意:需要基本身份验证的原因是使用提供的用户名和密码验证请求的真实性。我没有使用 X-Twilio-Signature HTTP header ,因为我无权访问身份验证 token 来验证请求,并且正在使用 api key 来发出请求。
最佳答案
我使用 Ngrok(启用了身份验证)进行了测试,并配置了 Twilio statusCallback 基本身份验证,并且它有效。尝试修改您的响应 header ,看看是否会发生任何变化。
Ngrok 返回以下响应 header :
HTTP/1.1 401 Unauthorized
Content-Length: 20
Content-Type: text/plain
Www-Authenticate: Basic realm="ngrok"
关于用于可编程短信状态回调 URL 的 Twilio HTTP 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61689105/