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


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:


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


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.


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


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


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.


use instead of localhost.
This helps in local development.


you can use http: to replace localhost


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

#9 is this right


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


I tried using 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!


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");

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

		String authorizationUrl = twitterRequestToken.getAuthorizationURL();
	catch (TwitterException e)
		throw new ServletException(e);


out with that? Thank you


try this


twitter work for local host


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


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


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?


You could use as the oauthback. It works for me .
You have to specify the port.


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