18
votes

Been trying to setup my Facebook app which I want to use for Logins to allow me to test it on my Mac's localhost. Facebook is throwing the error "App Domain: http://localhost is not a valid domain." when I try change App Domain of Site URL to localhost or 127.0.0.1

IS there any way to get the facebook login api to redirect the browser to my localhost after authentication?

3

3 Answers

17
votes

The way I do it is alias the site I'm working on to something like: http://sitename.loc, and then setup an app used specifically for testing with that as the domain.

An example of how to do this can be found here: https://stackoverflow.com/a/7493806/1056965

7
votes

On your local machine you have to setup hosts file to point your site name on local ip address. For example if you have to setup authorization with fb on site example.com put this record in your hosts file

127.0.0.1 example.com

And just start your site localy and facebook oauth will redirect you on example.com and you will get valid token localy.

For setup hosts file on windows help is on this link Windows Hosts Setup Linux help link Linux hosts

3
votes

It's simple enough when you find out.

Open /etc/hosts (unix) or C:\WINDOWS\system32\drivers\etc\hosts.

If your domain is foo.com, then add this line:

127.0.0.1 local.foo.com When you are testing, open local.foo.com in your browser and it should work.

Allready, explained here

How to Test Facebook Connect Locally