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


#1

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

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.


#3

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


#4

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


#5

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.


#6

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


#7

you can use http:127.0.0.1 to replace localhost


#8

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


#9

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


#10

@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.


#11

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 :frowning: 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!


#12

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:

	TwitterFactory twitterFactory;
	twitterFactory = new TwitterFactory();
	Twitter twitter = twitterFactory.getInstance();
	twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);


	StringBuffer callbackURL = request.getRequestURL();
	int index = callbackURL.lastIndexOf("/");
	callbackURL.replace(index, callbackURL.length(), "").append("/callback");

	try
	{
		RequestToken twitterRequestToken = twitter.getOAuthRequestToken(callbackURL.toString());
		request.getSession().setAttribute("requestToken", twitterRequestToken);

		String authorizationUrl = twitterRequestToken.getAuthorizationURL();
		response.sendRedirect(twitterRequestToken.getAuthenticationURL());
	}
	catch (TwitterException e)
	{
		throw new ServletException(e);
	}

#13

out with that? Thank you


#14

try this
http://127.0.0.1/


#15

twitter work for local host


#16

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


#17

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


#18

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?


#19

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


#20

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
:confused: