当在URL中指定用户名:密码格式时,Twilio不在标题中发送凭据

问题描述 投票:1回答:2

我目前正在开发我的应用程序,目前处于可以测试来自Twilio的消息的阶段。我在数字海洋上为服务器配置了公开的IP地址,而Nodejs应用程序正在侦听来自Twilio的呼叫。我还使用“ HTTP POST”将电话号码的消息“请求网址”配置为“ http://username:[email protected]/messages”。

调试标题时,看不到“授权”标题。我在这里想念什么吗?任何帮助深表感谢!下面是代码。

var headerValues = bag.req.headers.authorization.split(' ');

  console.log(bag.req.headers);

  var scheme = headerValues[0];
  if (scheme === 'Basic') {
    var credentials = headerValues[1];
    var decoded = new Buffer(credentials, 'base64').toString().split(':');
    bag.req.creds = {
      userName: decoded[0],
      password: decoded[1],
      authType: 'basic'
    }
  }
node.js authentication twilio basic-authentication digest
2个回答
0
投票

我使用与您建立的多个呼叫中心相同的设置。

如果您使用的代理设置需要在IP地址之前输入用户名:password @,那么您可以通过直接访问实际的服务器ip地址来访问代码(如我在下面所述),则可能是该代理的问题。但是,您没有提到仅使用数字海洋飞沫来使用代理,因此我在假设您没有代理设置的情况下做出回应。

因此,如果您有代理设置,请确保您可以直接直接访问服务器的IP地址。

此外,如果这些只是多余的变量,则需要传递给您,最好在IP地址后附加它们

例如xxx.xxx.xxx.xxx/用户名/密码

然后通过req.params获取它们

例如((是的,这将适用于发布数据,因为它只是URL的一部分,而不是实际的get命令发布)]

router.post('/sms/:username/:password'), function(req, res, next){
    username = req.params.username;
}

首先,您不希望使用“ HTTP POST”将请求URL指向“ http://username:[email protected]/messages”。

如果您没有指向您IP地址的域,但您希望您的请求URL是

https://198.xxx.xxx.xxx/inbound/sms

{用您使用的任何路由替换/ inbound / sms}

然后位于您路线的顶部(我正在使用快递,因此我的设置可能与您的设置有所不同]

我有node.js twilio库

  , twilio = require('twilio')
  , capability = new twilio.Capability(sid, auth)
  , client = require('twilio')(sid, auth)

然后这是我的/ sms路由的示例

router.post('/sms', function(req, res, next){
  var sid = req.body.SmsSid;
  var from = req.body.From;
  var to = req.body.To;
  var date = Date();
   var body = req.body.Body;
  if(req.body.NumMedia > 0){
    code to handle MMS
  }

    Code to handle SMS data
   res.send("Completed");
 });

0
投票

我本周遇到这个问题,发现URL中有关基本身份验证的行为非常模糊。一方面,由于它与HTTP有关,因此似乎已不推荐使用URI spec

...
3.2.1.  User Information
...
Use of the format "user:password" in the userinfo field is deprecated.
...7.5.  Sensitive Information

URI producers should not provide a URI that contains a username or password that is intended to be secret.  URIs are frequently displayed by browsers, stored in clear text bookmarks, and logged by user agent history and intermediary applications (proxies).  A password appearing within the userinfo component is deprecated and should be considered an error (or simply ignored) except in those rare cases where the 'password' parameter is intended to be public.
...

因此,Firefox和Chrome似乎都将其剥离并忽略了它。但是,Curl似乎将其转换为有效的Authorization标头。

无论如何,我相信此功能实际上是HTTP用户代理的责任,并且看来Twilio的用户代理没有完成其工作。因此,无法进行基本身份验证。

但是,看来Twilio的首选身份验证方法是仅使用您帐户的秘密身份验证密钥对请求进行签名,然后您可以在处理请求时进行验证。参见here

在研究原始NodeJS RequestIncomingMessage类时,似乎没有办法获取完整的原始URL来补偿Twilio的不符合项。我相信这是因为HTTP请求的实际数据不包含完整的URL。

我的理解是,实际上是HTTP 用户代理负责从URL中提取和格式化身份验证信息。也就是说,一致的HTTP用户代理应解析URL本身,使用主机名和端口部分在正确的机器上找到正确的门,使用协议部分建立与侦听器的连接,将动词与URL的路径部分结合使用指示要激活什么功能,然后大概负责将URL的auth部分转换为正式的HTTP Authorization标头。

缺少用户代理的工作,无法将身份验证数据获取到您的系统中。

(这是我目前的理解,尽管可能并不完全准确。其他人可以随时发表评论或纠正。)

© www.soinside.com 2019 - 2024. All rights reserved.