OAuth:如何使用本地 URL 进行测试? [英] OAuth: how to test with local URLs?
问题描述
我正在尝试测试 OAuth 按钮,但它们都是(Facebook、Twitter、LinkedIn)返回的错误似乎表明我无法从 本地 URL 测试或使用它们.
I am trying to test OAuth buttons, but they all (Facebook, Twitter, LinkedIn) come back with errors that seem to signal that I can not test or use them from a local URL.
如果人们似乎都需要非开发和非本地连接环境,那么他们通常如何使用 OAuth 进行开发?
How do people usually work in development with OAuth stuff if they all seem to require a non-dev and non-local connections environments?
推荐答案
2016 年 10 月更新:现在最简单:使用 lvh.me 始终指向 127.0.0.1
.
Update October 2016: Easiest now: use lvh.me which always points to 127.0.0.1
.
上一个答案:
由于回调请求是由浏览器发出的,因此作为 HTTP 重定向响应,您可以设置 .hosts 文件或等效文件,将不是 localhost
的域指向 127.0.0.1.
Since the callback request is issued by the browser, as a HTTP redirect response, you can set up your .hosts file or equivalent to point a domain that is not localhost
to 127.0.0.1.
例如,您在 Twitter 上注册了以下回调:http://www.publicdomain.com/callback/
.确保 www.publicdomain.com
在您的主机文件中指向 127.0.0.1,并且 twitter 可以在 www.publicdomain.com,即域需要存在,并且如果请求,特定的回调可能应该返回 200 状态消息.
Say for example you register the following callback with Twitter: http://www.publicdomain.com/callback/
. Make sure that www.publicdomain.com
points to 127.0.0.1 in your hosts file, AND that twitter can do a successful DNS lookup on www.publicdomain.com, i.e the domain needs to exist and the specific callback should probably return a 200 status message if requested.
编辑:
我刚刚阅读了以下文章:http://www.tonyamoyal.com/2009/08/17/how-to-quickly-set-up-a-test-for-twitter-oauth-authentication-from-your-local-machine,从这个问题链接到:Twitter oAuth callbackUrl - 本地主机开发.
I just read the following article: http://www.tonyamoyal.com/2009/08/17/how-to-quickly-set-up-a-test-for-twitter-oauth-authentication-from-your-local-machine, which was linked to from this question: Twitter oAuth callbackUrl - localhost development.
引用文章:
您可以使用 bit.ly,一种 URL 缩短服务.只需缩短 [localhost URL,例如 http//localhost:8080/twitter_callback] 并将缩短的 URL 注册为 Twitter 应用程序中的回调.
You can use bit.ly, a URL shortening service. Just shorten the [localhost URL such as http//localhost:8080/twitter_callback] and register the shortened URL as the callback in your Twitter app.
这应该比在 .hosts 文件中摆弄更容易.
This should be easier than fiddling around in the .hosts file.
请注意,现在(14 年 8 月)bit.ly 不允许将链接转发到本地主机;但是 Google 链接缩短器可以工作.
Note that now (Aug '14) bit.ly is not allowing link forwarding to localhost; however Google link shortener works.
PS (18 年 11 月):Google 链接缩短器停止支持 localhost 或 127.0.0.1.
PS edit: (Nov '18): Google link shortener stopped giving support for localhost or 127.0.0.1.
这篇关于OAuth:如何使用本地 URL 进行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!