OAuth:如何使用本地网址进行测试? [英] OAuth: how to test with local URLs?
问题描述
我正在尝试测试 OAuth 按钮,但它们都是(Facebook,Twitter,LinkedIn)出现错误,似乎表明我无法从 local 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.
如果人们似乎都需要 non-dev 和 non-local 连接环境,人们通常如何使用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
指向您的hosts文件中的127.0.0.1,并且twitter可以在www.publicdomain.com上成功进行DNS查找,即该域需要存在,并且特定的回调可能返回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.
编辑:
我刚刚阅读了以下文章: Twitter oAuth callbackUrl-localhost开发.
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.
引用该文章:
您可以使用URL缩短服务bit.ly.只需缩短[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(2008年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:如何使用本地网址进行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!