Twitter oAuth callbackUrl - localhost development
Twitter oAuth callbackUrl - localhost development
Is anyone else having a difficult time getting Twitters oAuth's callback URL to hit their localhost development environment.
Apparently it has been disabled recently. http://code.google.com/p/twitter-api/issues/detail?id=534#c1
Does anyone have a workaround. I don't really want to stop my development
17 Answers
17
Alternative 1.
Set up your .hosts (Windows) or etc/hosts file to point a live domain to your localhost IP. such as:
127.0.0.1 xyz.com
where xyz.com is your real domain.
Alternative 2.
Also, the article gives the tip to alternatively use a URL shortener service. Shorten your local URL and provide the result as callback.
Alternative 3.
Furthermore, it seems that it works to provide for example http://127.0.0.1:8080
as callback to Twitter, instead of http://localhost:8080
.
http://127.0.0.1:8080
http://localhost:8080
Good point and thank you.
– Tony
May 21 '12 at 6:31
127.0.0.1:3000 works like a charm.
– JacopKane
Jul 22 '12 at 19:58
Could this be causing the following error: The remote server returned an error: (401) Unauthorized?
– DevDave
Feb 1 '13 at 18:20
How does localhost work when there is no tunnel to it? It doesn't actually hit ur local machine?
– Jack Tuck
Mar 28 '16 at 22:56
I just had to do this last week. Apparently localhost
doesn't work but 127.0.0.1
does Go figure.
localhost
127.0.0.1
This of course assumes that you are registering two apps with Twitter, one for your live www.mysite.com
and another for 127.0.0.1
.
www.mysite.com
127.0.0.1
really odd why this happens .. but does work for me ..thanks
– Archan Mishra
Apr 9 '12 at 5:48
Just put http://127.0.0.1:xxxx/ as the callback url, where xxxx is the port for your framework
Yes, it was disabled because of the recent security issue that was found in OAuth. The only solution for now is to create two OAuth applications - one for production and one for development. In the development application you set your localhost callback URL instead of the live one.
I just tried doing that, but it doesn't accept localhost:3000 as a URL format...
– David N. Welton
Jun 9 '09 at 21:59
Yes, they seem to filter such URLs. :( But the support for custom callback urls is back - maybe they're supported there.
– arikfr
Jul 7 '09 at 20:11
This is how i did it:
Registered Callback URL:
http://127.0.0.1/Callback.aspx
OAuthTokenResponse authorizationTokens =
OAuthUtility.GetRequestToken(ConfigSettings.getConsumerKey(),
ConfigSettings.getConsumerSecret(),
"http://127.0.0.1:1066/Twitter/Callback.aspx");
ConfigSettings:
public static class ConfigSettings
{
public static String getConsumerKey()
{
return System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"].ToString();
}
public static String getConsumerSecret()
{
return System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"].ToString();
}
}
Web.config:
<appSettings>
<add key="ConsumerKey" value="xxxxxxxxxxxxxxxxxxxx"/>
<add key="ConsumerSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>
</appSettings>
Make sure you set the property 'use dynamic ports' of you project to 'false' and enter a static port number instead. (I used 1066).
I hope this helps!
Use http://smackaho.st
What it does is a simple DNS association to 127.0.0.1 which allows you to bypass the filters on localhost or 127.0.0.1 :
smackaho.st. 28800 IN A 127.0.0.1
So if you click on the link, it will display you what you have on your local webserver (and if you don't have one, you'll get a 404). You can of course set it to any page/port you want :
http://smackaho.st:54878/twitter/callback
this is a dead link now
– Paul
Dec 29 '11 at 4:06
It's not dead. . . .
– Mob
Dec 29 '11 at 9:50
smackaho.st is no longer available tbaggery.com/2010/03/04/smack-a-ho-st.html. Use lvh.me instead. It goes directly to localhost.
– Justin
May 25 '12 at 16:15
Callback URL edited
http://localhost:8585/logintwitter.aspx
Convert to
http://127.0.0.1:8585/logintwitter.aspx
I was working with Twitter callback url on my localhost. If you are not sure how to create a virtual host ( this is important ) use Ampps. He is really cool and easy. In a few steps you have your own virtual host and then every url will work on it. For example:
download and install ampps
Add new domain. ( here you can set for example twitter.local) that means your virtual host will be http://twitter.local and it will work after step 3.
I am working on Win so go under to your host file -> C:WindowsSystem32Driversetchosts and add line: 127.0.0.1 twitter.local
Restart your Ampps and you can use your callback. You can specify any url, even if you are using some framework MVC or you have htaccess url rewrite.
Hope This Help!
Cheers.
Thanks for the tip. On linux, just add the development domain name to /etc/hosts
– jeremyvillalobos
Apr 23 '14 at 2:05
When I develop locally, I always set up a locally hosted dev name that reflects the project I'm working on. I set this up in xampp through xamppapacheconfextrahttpd-vhosts.conf and then also in WindowsSystem32driversetchosts.
So if I am setting up a local dev site for example.com, I would set it up as example.dev in those two files.
Short Answer: Once this is set up properly, you can simply treat this url (http://example.dev) as if it were live (rather than local) as you set up your Twitter Application.
A similar answer was given here: https://dev.twitter.com/discussions/5749
Direct Quote (emphasis added):
You can provide any valid URL with a domain name we recognize on the
application details page. OAuth 1.0a requires you to send a
oauth_callback value on the request token step of the flow and we'll
accept a dynamic locahost-based callback on that step.
This worked like a charm for me. Hope this helps.
It can be done very conveniently with Fiddler:
127.0.0.1 your-production-domain.com
A pleasant bonus is that you can specify a custom port, like this:127.0.0.1:3000 your-production-domain.com
(it would be impossible to achieve this via the hosts file). Also, instead of IP you can use any domain name (e.g., localhost
).
127.0.0.1:3000 your-production-domain.com
localhost
This way, it is possible (but not necessary) to register your Twitter app only once (provided that you don't mind using the same keys for local development and production).
edit this function on TwitterAPIExchange.php at line #180
public function performRequest($return = true)
{
if (!is_bool($return))
{
throw new Exception('performRequest parameter must be true or false');
}
$header = array($this->buildAuthorizationHeader($this->oauth), 'Expect:');
$getfield = $this->getGetfield();
$postfields = $this->getPostfields();
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
);
if (!is_null($postfields))
{
$options[CURLOPT_POSTFIELDS] = $postfields;
}
else
{
if ($getfield !== '')
{
$options[CURLOPT_URL] .= $getfield;
}
}
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
if ($return) { return $json; }
}
You can download TwitterAPIExchange.php from here github.com/J7mbo/twitter-api-php
– Helper
Sep 11 '13 at 7:02
I had the same challenge and I was not able to give localhost as a valid callback URL. So I created a simple domain to help us developers out:
https://tolocalhost.com
It will redirect any path to your localhost domain and port you need. Hope it can be of use to other developers.
Excellent resource, But your domain adds "/" to the end of url which leads to 404 on some occasions. could you please fix it? For example it redirects as "localhost/somename/?<response>, but it should be "localhost/somename?<response>
– Channa
Feb 5 at 6:36
@Channa I tried to reproduce this but it seems that the script works correctly. What browser are you using? I tried Chrome, Safari, Firefox and it works like expected.
– Jørgen
Feb 5 at 8:45
It happens to me in both Chrome and Firefox. This is the hostname I put in your page "localhost:8080/dashboard/twitterRedirect.jsp" But when it redirects it goes to "localhost:8080/dashboard/twitterRedirect.jsp/…; Please note the "/" symbol before the question mark. It will cause my app to send me 404
– Channa
Feb 5 at 9:21
@Channa you should not put the whole URL in the hostname field. It is called: hostname, not URL ;-) The idea is to be able to override 'localhost' to something like: my.localhost.bla then it will use that instead of localhost. In your case the host field needs to be localhost. You set the port to 8080 and configure the redirect to go to: tolocalhost.com/dashboard/twitterRedirect.jsp this will redirect to: localhost:8080/dashboard/twitterRedirect.jsp
– Jørgen
Feb 5 at 10:40
got it. works like a charm
– Channa
Feb 6 at 5:29
set callbackurl in twitter app : 127.0.0.1:3000
and set WEBrick to bind on 127.0.0.1 instead of 0.0.0.0
command : rails s -b 127.0.0.1
Looks like Twitter now allows localhost
alongside whatever you have in the Callback URL
settings, so long as there is a value there.
localhost
Callback URL
I struggled with this and followed a dozen solutions, in the end all I had to do to work with any ssl apis on local host was:
Go download: cacert.pem file
In php.ini
* un-comment and change:
curl.cainfo = "c:/wamp/bin/php/php5.5.12/cacert.pem"
php.ini
curl.cainfo = "c:/wamp/bin/php/php5.5.12/cacert.pem"
php.ini
php --ini
These are the steps that worked for me to get Facebook working with a local application on my laptop:
Seems nowadays http://127.0.0.1
also stopped working.
A simple solution is to use http://localtest.me
instead of http://localhost
it is always pointing to 127.0.0.1
And you can even add any arbitrary subdomain to it, and it will still point to 127.0.0.1
http://127.0.0.1
http://localtest.me
http://localhost
127.0.0.1
127.0.0.1
See Website
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
It worked for me by setting twitter callback url to my real website url. While testing in localhost -> twitter signup, redirected to localhost (instead of website url).
– Sudhakar Krishnan
Aug 22 '16 at 8:01