简体   繁体   English

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

[英]Twilio is not sending creds in headers when specifying username:password format in the URL

I'm currently developing my app and I'm at the stage where I can start testing messages from Twilio.我目前正在开发我的应用程序,我正处于可以开始测试来自 Twilio 的消息的阶段。 I configured my server on digital ocean with a public facing IP address and my Nodejs app is listening to calls from Twilio.我使用面向公众的 IP 地址在数字海洋上配置了我的服务器,我的 Nodejs 应用程序正在监听来自 Twilio 的调用。 I also configured my phone number's message "request url" to " http://username:password@198.xxx.xxx.xxx/messages " with "HTTP POST".我还使用“HTTP POST”将我的电话号码的消息“请求 url”配置为“ http://username:password@198.xxx.xxx.xxx/messages ”。

When I debug the headers, I don't see the "authorization" headers.当我调试标头时,我没有看到“授权”标头。 I'm I missing something here?我在这里错过了什么? Any help is much appreciated.任何帮助深表感谢。 Below is the code.下面是代码。

 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' } }

I use the same setup as you do in several call centers I have built.我使用的设置与您在我建立的几个呼叫中心中所做的设置相同。

If you are using a proxy setup which requires username:password@ before the IP address then your issue is likely with that proxy if you can access the code by going directly to the actual server ip address as I note below.如果您使用的代理设置需要 username:password@ 在 IP 地址之前,那么如果您可以通过直接转到实际服务器 ip 地址来访问代码,那么您的问题可能与该代理有关,如下所示。 However, you did not mention using a proxy just using a digital ocean droplet so I am responding assuming you do not have a proxy setup.但是,您没有提到仅使用数字海洋水滴使用代理,所以我假设您没有设置代理。

So if you do have a proxy setup make sure you can access the IP address of the server directly first.因此,如果您确实设置了代理,请确保您可以先直接访问服务器的 IP 地址。

Also if those are just extra variables you need to pass over you may be better off appending them after the IP address此外,如果这些只是您需要传递的额外变量,您最好将它们附加在 IP 地址之后

for instance xxx.xxx.xxx.xxx/username/password例如 xxx.xxx.xxx.xxx/用户名/密码

Then get them with req.params然后用 req.params 获取它们

for instance (and yes this will work with post data since its merely part of the URL and not an actual get command post)例如(是的,这将与发布数据一起使用,因为它只是 URL 的一部分,而不是实际的 get 命令发布)

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

First you would not want to direct your request URL at " http://username:password@198.xxx.xxx.xxx/messages " with "HTTP POST".首先,您不想使用“HTTP POST”将您的请求 URL 指向“ http://username:password@198.xxx.xxx.xxx/messages ”。

If you do not have a domain directed at your IP address yet you want your request URL to be如果您没有指向您的 IP 地址的域,但您希望您的请求 URL 是

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

{Replacing /inbound/sms with whatever route you are using} {用你正在使用的任何路由替换/inbound/sms}

Then at the top of your route (I am using express so my setup may look different than your)然后在你的路线的顶部(我使用的是 express,所以我的设置可能看起来与你的不同)

I have the node.js twilio library我有 node.js twilio 库

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

Then here is an example of my /sms route然后这是我的 /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");
 });

I ran into this this week and discovered that behavior surrounding Basic Auth in the URL is very cloudy.这周我遇到了这个问题,发现 URL 中围绕 Basic Auth 的行为非常模糊。 For one thing, it appears to be deprecated from the URI spec as it pertains to HTTP:一方面,它似乎已从URI 规范中弃用,因为它与 HTTP 相关:

...
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.
...

Because of this, both Firefox and Chrome appear to just strip it out and ignore it.因此,Firefox 和 Chrome 似乎只是将其删除并忽略它。 Curl, however, seems to convert it to a valid Authorization header.然而,Curl 似乎将其转换为有效的Authorization标头。

Whatever the case, I believe this functionality is actually the responsibility of the HTTP user agent, and it appears that Twilio's user agent is not doing its job.无论如何,我相信这个功能实际上是 HTTP 用户代理的责任,而且 Twilio 的用户代理似乎没有完成它的工作。 Thus, there is no way to make basic auth work.因此,没有办法使基本身份验证工作。

However, it appears Twilio's preferred method of auth is to simply sign the request using your account's secret auth key, which you can then verify when handling the request.但是,似乎 Twilio 的首选身份验证方法是使用您帐户的秘密身份验证密钥简单地签署请求,然后您可以在处理请求时验证该密钥。 See here .这里

On researching the raw NodeJS Request and IncomingMessage classes, there appears to be no way to get at the full, raw URL to compensate for Twilio's non-conformity.在研究原始 NodeJS RequestIncomingMessage类时,似乎无法获得完整的原始 URL 来弥补 Twilio 的不符合性。 I believe this is because the actual data of an HTTP request doesn't contain the full URL.我相信这是因为 HTTP 请求的实际数据不包含完整的 URL。

My understanding is that it's actually the HTTP user agent that's responsible for extracting and formatting the auth info from the URL.我的理解是,实际上是 HTTP用户代理负责从 URL 中提取和格式化身份验证信息。 That is, a conformant HTTP user agent should parse the URL itself, using the hostname and port portion to find the right door on the right machine, the protocol portion to establish the connection with the listener, the verb combined with the URL's path portion to indicate what functionality to activate, and presumably it is then responsible for converting the auth section of the URL to an official HTTP Authorization header.也就是说,符合 HTTP 的用户代理应该解析 URL 本身,使用主机名和端口部分在正确的机器上找到正确的门,使用协议部分来建立与侦听器的连接,动词结合 URL 的路径部分来指示要激活的功能,然后大概它负责将 URL 的 auth 部分转换为官方 HTTP Authorization标头。

Absent that work by the user agent, there is no way to get the auth data into your system.如果没有用户代理的工作,就无法将授权数据获取到您的系统中。

(This is my current understanding, although it may not be totally accurate. Others, feel free to comment or correct.) (这是我目前的理解,虽然可能不完全准确。其他人,欢迎评论或指正。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM