使用 ngrok url 作为 facebook webhook 的回调 url,但被识别 "not whitelisted"

Use ngrok url as callback url for facebook webhook, but is recognized "not whitelisted"

我的 IDE 是 Pycharm。 我想在本地测试我的应用程序,所以我 运行 在本地使用我的服务并使用 ngrok 将我的应用程序公开到 Internet。

ngrok显示的url是https://436cb7e9.ngrok.io

但是当我想验证 facebook webhook 回调 url 使用上面这个 url 时,它显示

ERROR 2017-12-27 08:16:37,407 wsgi_server.py:329] Request Host 436cb7e9.ngrok.io not whitelisted. Enabled hosts are set(['localhost'])

我运行这个应用程序之前很好,但我不知道为什么这次它显示错误。 有人可以给我建议吗?

这是通过 ngrok 仪表板的 Auth 选项卡完成的。来自 IP Whitelisting Tunnel Access:

You may whitelist access to tunnel endpoints on your account. The whitelist is enforced by the ngrok.com servers. It is applied globally to all of your tunnel endpoints. Any incoming connection to any of your tunnel endpoints is checked to guarantee that the source IP address of the connection matches at least one entry in your whitelist. If a connection does not match the whitelist it is terminated immediately and never forwarded to an ngrok client.

As a special case, if your whitelist is empty, all connections are allowed.

Managing the whitelist

You can manage the IP whitelist on the auth tab of your ngrok dashboard. Enter a new IP address under the "IP Whitelist" section and then click Add Whitelist Entry. Changes to the IP Whitelist can take up to 30 seconds to take effect.

IP Ranges

Sometimes, you may wish to whitelist an entire range of IPs. Instead of entering just a single IP address, you may instead specify a block of IP addresses using CIDR notation. For example, to allow all IP addresses from 10.1.2.0 to 10.1.2.255, you would add 10.1.2.0/24 to your whitelist.

经过一番挖掘并感谢 Brady 关于 gcloud 版本的评论,我发现解决此问题所需要做的就是在 运行 您的应用程序时添加一个标志。

所以,假设您 运行 您的应用在本地使用:

python $APPENGINE/dev_appserver.py

只需将其更改为:

python $APPENGINE/dev_appserver.py --enable_host_checking=false

你应该不会再有主机白名单错误了。

有关详细信息,请在此处查看发行说明:https://cloud.google.com/appengine/docs/standard/python/release-notes#december_5_2017

这对我来说似乎在 gcloud 183.0.0 和 187.0.0(撰写此评论时的最新版本)上运行良好。

我有一个稍微不同的问题,但是 google 引导我到这里 none 更少,我的错误是:

“无法验证回调 URL 或验证令牌。请验证提供的信息或稍后重试。”

尝试将 facebook webhook 连接到我的本地主机时。结果我需要验证我的 ngrok 代理: https://dashboard.ngrok.com/get-started/your-authtoken