Why can't I use localhost as my OAuth callback?

laserlemon
@laserlemon Steve Richert

GitHub OAuth conveniently allows you to specify a "localhost" callback URL for use in local development. I'm getting an invalid error for the following callback URL:

http://localhost:3000/auth/twitter/callback

and I assume it's because of the localhost (or maybe the port). Could you help me out with that? Thank you!

2 years 9 weeks ago

Replies

episod
@episod Taylor Singletary

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.

2 years 9 weeks ago
marqia_lynn
@marqia_lynn marqia williams

I keep getting invalid url callback when I enter a valid callback url. In addition, it will not allow me to leave it blank.

2 years 4 weeks ago
BenJohnstonSF
@BenJohnstonSF ben johnston

i am getting the same problem as @marqia_lynn. Why would twitter not just let you put in localhost?

2 years 3 weeks ago
episod
@episod Taylor Singletary

The OAuth callback field on your app management screen is just a placeholder! Treat it as if it means nothing, and that you just need to put a valid URL there in order to use callback-based auth. Try putting "http://yourusername.com".

In OAuth 1.0a, you are required to send an oauth_callback parameter to the oauth/request_token every time, regardless of what you put in this field. At the oauth/request_token step, you can provide a http://localhost/blah/blah/blah callback if you like. You just can't associate localhost with your application record on dev.twitter.com.

2 years 3 weeks ago
AmbiAdh
@AmbiAdh msPerfect

use http://127.0.0.1 instead of localhost.
This helps in local development.

1 year 44 weeks ago
Sir03834855
@Sir03834855 咔咔Sir

you can use http:127.0.0.1 to replace localhost

1 year 43 weeks ago
Rick24Sharma
@Rick24Sharma Rick Sharma

why should not we use our local host server for the connection

1 year 32 weeks ago
GDBalaji
@GDBalaji Balaji GD

http://127.0.0.1.folder_name.com/folder_name is this right

1 year 27 weeks ago
SBTDev
@SBTDev SBTDev

@GDBalaji: You should use http://127.0.0.1/folder_name for this. When you use an IP address in a URL, the IP is put in place of the domain, not before it.

1 year 27 weeks ago
nihase123
@nihase123 senthilkumar kumaran

I tried using http://127.0.0.1/folder_name but no use, it is throwing "Not a valid URL format". I'm not sure how to configure this. This is frustrating me :( and please note that this issue is still OPEN. Can anybody help me to fix this. Suggestions would be really helpful to me, as i'm working in Oauth and struggling to configure APIv1.1 in my localhost. thanks in advance!

39 weeks 1 day ago
cjmcguinness
@cjmcguinness Charles McGuinness

It doesn't matter what you put into the settings for your app. Put in the URL of your website, for example. Just pass along your localhost callback in the actual API call to authorize. I actually write my code in a way that it looks at the current URL to generate a callback URL, so the code works unchanged whether testing on my PC or on the server in the cloud.

As an example, if you are using Java Servlets (which you are probably not, but...), you can use code like this:

  1.         TwitterFactory twitterFactory;
  2.      twitterFactory = new TwitterFactory();
  3.      Twitter twitter = twitterFactory.getInstance();
  4.         twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
  5.  
  6.  
  7.      StringBuffer callbackURL = request.getRequestURL();
  8.         int index = callbackURL.lastIndexOf("/");
  9.         callbackURL.replace(index, callbackURL.length(), "").append("/callback");
  10.  
  11.      try
  12.         {
  13.           RequestToken twitterRequestToken = twitter.getOAuthRequestToken(callbackURL.toString());
  14.            request.getSession().setAttribute("requestToken", twitterRequestToken);
  15.  
  16.          String authorizationUrl = twitterRequestToken.getAuthorizationURL();
  17.            response.sendRedirect(twitterRequestToken.getAuthenticationURL());
  18.      }
  19.       catch (TwitterException e)
  20.      {
  21.           throw new ServletException(e);
  22.      }
39 weeks 1 day ago
Peggy6668
@Peggy6668 PeggyLin

out with that? Thank you

35 weeks 5 days ago
Smart_Casper
@Smart_Casper Casper Smart

try this
http://127.0.0.1/

24 weeks 1 day ago
IkoRubio
@IkoRubio vinz iko rubio

twitter work for local host

4 weeks 6 hours ago
chleozam
@chleozam Karen Farzam

same with me, I used the localhost but can not have it work...

19 weeks 3 days ago
chleozam
@chleozam Karen Farzam

you can open a file from the terminal in order to change the local host name:
$ subl /etc/hosts
you might need to use the super user to get access, in such a case do this in the terminal:
$ sudo vi /etc/hosts
then you can just change the name localhost to my-localhost.com

19 weeks 1 day ago
Ghodmode
@Ghodmode Vince Aggrippino

Okay. I've read this whole thread and, to me, it's about as clear as mud. I realize that it's an old thread and that configuration options may have changed.

In the Twitter app configuration there's a field for a callback URL on the Settings tab. I realize that we can't put a localhost domain there.

On the OAuth tool tab, there's a Request Settings block with two fields: Request URI and Request query. The Request URI field is automatically populated with https://api.twitter.com/1/. This seems to make sense since we're making a request to the Twitter API.

The Request query isn't for a full URL. It's just the part after the question mark in a URL which we might not even use for our application.

So, is the correct procedure to put our localhost callback URL into the Request URI field?

17 weeks 5 days ago
sarathsprakash
@sarathsprakash sarathsreeprakash

You could use http://127.0.0.1:8080/foldername as the oauthback. It works for me .
You have to specify the port.

16 weeks 5 days ago
fbncs
@fbncs Fabiano

it doesn't work on windows 8.1...

the loopback IP is ::1 (ipv6), and 127.0.0.1:xxx returns invalid url format...

:/

12 weeks 3 days ago
cseer90
@cseer90 Sayed Ahad Abbas

nothing, as suggested by anyone of you above, is working and I'm still stuck with creation of a sample login app. I'm trying to create it for localhost but it says
Not a valid URL format
:/

14 weeks 6 days ago
GombertM
@GombertM Gombi

Hello everybody.
To my point of view, this is frankly restrictive. I am stucked for 3 days on this issue of localhost redirection. I'm really disappointed. If someone has a real trick to escape from this problem, i'd be recognicient. Thanks per advance

12 weeks 4 days ago
fbncs
@fbncs Fabiano

http://127.0.0.1:xxx/ not working on windows 8.1, i think because ipv6 it's activated, and I'm having errors...

I try to navigate on browser, or ping, and I'm receaving a bad request url... invalid format.

I've discovered that doing a ping to localhost, and the IP is ::1

12 weeks 3 days ago
ArpillePointCom
@ArpillePointCom Arpille.com

I have put http://arpille.com inthe URL callback,
and error red message : Invalid URL
Whet does this field ask for ?
I tried a domain, I tried a full file adress with domain,
Same error.
Thanks for help.

12 weeks 1 day ago
30thJune1986
@30thJune1986 OMG, That B.A.S.E!!

I had been using http:127.0.0.1:8888/auth/twitter/callback

Worked fine until it stopped working... my access token are suddenly not recognized anymore. Wondering if it is because they are passed as argument of the aformentioned callback url.

I'm really clueless as I haven't changed the code at all.

11 weeks 4 days ago
sumitjasuja90
@sumitjasuja90 Sumit jasuja

i have given call back url in request but twitter api returning on url that is mentioned in app setting. i want twitter to return on url given in code. how do i can do ?

2 weeks 6 days ago