98

I've been writing a game for Facebook using Rails and jQuery. Since I started using the Facebook Javascript SDK, using localhost as an app domain seemed to work just fine. I was able to test my game both locally and on Heroku.

In the past day, it seems that Facebook has made a big update to their developer UI. Now if I add localhost as an app domain, it gives me the following error:

This must be derived from Canvas URL, Secure Canvas URL, Site URL, Mobile Site URL, Page Tab URL or Secure Page Tab URL. Check and correct the following domains: localhost

My game also now doesn't work locally and I get an error when the Javascript SDK logs in the user:

API Error Code: 191 API Error Description: The specified URL is not owned by the application Error Message: Invalid redirect_uri: Given URL is not allowed by the Application configuration.

This doesn't happen when I deploy my game, since herokuapp.com is considered a valid app domain.

How am I supposed to develop and test my game if I can no longer use localhost or 127.0.0.1?

4
  • What values do you have for Canvas URL, Secure Canvas URL, Site URL, Mobile Site URL, Page Tab URL or Secure Page Tab URL ?
    – Igy
    Jan 23, 2014 at 0:13
  • 2
    hey guys i got it, you have to create a new "test app", they should f*****g mention it on the app settings page, 1h of search to finally make it work on localhost:port Oct 12, 2015 at 22:29
  • @LouisGrellet, Well, I'm getting "Top-level domains are not allowed". Like you said, f*****g May 11, 2017 at 7:50
  • 1
    "Under Client oAuth settings, where it says Use Strict Mode for Redirect URIs make sure it’s set to No and the hit save." -- wp-native-articles.com/blog/news/…
    – eflat
    Oct 11, 2017 at 18:41

16 Answers 16

244

The protocol seems to keep changing, and the accepted answer didn't work for me today. In case it helps other searchers, this is what did work for me:

  • All changes were made on the Settings page under the Basic tab

1.) In the center under the first box of options, click "+ Add Platform" and choose "Website" (or whatever is appropriate for your app.)

2.) In the box that comes up for the website you just added: Site URL: http://localhost:3000/

3.) In the box above that (Settings => Basic): App Domain: localhost

4.) At the bottom right - click "Save Changes"

5.) Make sure you have the app ID copied and pasted correctly into your code. (The ID is in the first box on that page if you need it again.)

8
  • 1
    Thank you for updating the answer. Indeed, it seems that the original answer no longer works(still, thank you for your original answers Camilo and rareclass). It's a shame that Facebook never seems to announce these changes. Jun 16, 2014 at 22:16
  • 28
    Note that your URL must also be listed in Settings > Advanced > Valid OAuth redirect URIs. Sep 15, 2014 at 15:13
  • 4
    This doesn't seem to work anymore :( I get URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings. Make sure Client and Web OAuth Login are on and add all your app domains as Valid OAuth Redirect URIs. Feb 16, 2017 at 18:26
  • 4
    You're not allowed to use 'http' anymore. It's gotta be 'https'.
    – iJames
    Jun 7, 2018 at 8:10
  • 3
    This answer is no longer correct. You cannot use localhost in the app domains box under basic settings Apr 12, 2019 at 23:03
33
  1. Go to your App's settings page in http://developers.facebook.com
  2. Click on the dropdown arrow on the top left (next to the name of your app) and click "Create Test App" and give it a name
  3. In the Settings > Basic of that new Test App set the App Domains as "localhost"
  4. Also set the Website Site URL as "http://localhost:8888" (or whatever port you are using).
  5. IMPORTANT: this app has different App ID and App Secret from your online application. So, last step: make sure that you update the code that sits in your localhost with the Test App's App ID and App Secret. On the contrary, the code that sits in the live server should be using the main App's ID and Secret.
2
  • Most sensible/modern solution vs. trying to configure your prod account to also work with a dev env. Aug 5, 2019 at 18:10
  • This is the right answer as of October 2021 Oct 19, 2021 at 8:57
13

You can still test your app without deploying it on a remote sever like heroku. The trick is to update the etc/hosts file this way:

127.0.0.1 mydomain.com

Then on the Facebook App's settings, type [http://] mydomain.com, without the "[" and "]"

It worked for me this way

3
  • It won't work if you use a non-standard port which is usually what people do if they develop many apps in parallel.
    – mgol
    Nov 14, 2016 at 9:51
  • 1
    It will work, I used python -m SimpleHTTPServer to serve on port 8000, and example.com:8000/test-facebook.html, provided the expected result. I make the assumption that you registered 127.0.0.1 example.com in the /etc/hosts
    – Patrick
    May 7, 2017 at 13:17
  • Good to know! So they seem to ignore the port then, weird.
    – mgol
    May 17, 2017 at 8:35
9

For everybody who is fidgeting with this in 2017. The interface changed again. I wanted to comment this to the answer but I don't have enough reputation. The localhost url of your app now has to be copied to three places. Currently, (October 26th, 2017) the sequence is:

1.) Click "Settings" in the left menu.

2.) In the center under the first box of options, click "+ Add Platform" and choose "Website" (or whatever is appropriate for your app.)

3.) In the box that comes up for the website you just added copy your localhost site url (f.e. http://localhost:3000/)

4.) In the box above that "App Domain" copy the same URL

5.) At the bottom right - click "Save Changes"

6.) In the left menu under "Products" click "Facebook Login" (or add it via "+ Add Products" if it is not available)

7.) You are now in the Facebook Login settings. Copy the same url to the field "Valid OAuth redirect URIs"

This should work.

1
  • 2
    Note that Facebook no longer allows "http" for Valid OAuth Redirect URIs
    – OmNiOwNeR
    Oct 13, 2018 at 23:25
5

Just add localhost as your canvas url or mobile site url, this will allow you to have both localhost and herokuapp.com in your App Domain setting. Then once your app is in production, just remove it.

0
5

This is wrong way. You must create a test application using Test tab in app settings. And then you can enter your development stage url (for example localhost) to your application.

2
5

Solution using Firebase

In order to get this working on localhost, port 3000 I did the following:

  1. Create App

Create Test App

  1. Now Select "+ Create Test App" from the arrow dropdown (top left).

enter image description here

  1. Add localhost to App Domains

enter image description here

  1. Add http://localhost:3000/ to Site URL by selected "+ Add Platform"

enter image description here

Up to this point I had followed all previous answers submitted on here, but nothing worked.

So...

  1. In the left hand menu, select "Add Product"

  2. Add "Facebook Login"

You will be presented with a workflow carrousel, with defaulted domain http://localhost:3000/, click "continue" until the end.

  1. Select "Facebook Login > Settings" from the Product Menu.

  2. Enter your Firebase OAuth redirect URI (found when enable Facebook Login in your firebase console https://console.firebase.google.com, example below)

enter image description here

  1. Paste URI and Save.

enter image description here

Done.

2

Try using the url with port, e.g.

    http://localhost:8000/

I was having the same issue and found this solution right now.

1
  • 1
    You need to add 'App on Facebook' as platform, and add localhost:8000 into Canvas URL
    – Tachun Lin
    Jun 9, 2014 at 7:59
2

After straggling with this for a while I found a solution that combines few answers from this question. I guess that things constantly change when it comes to things like Facebook apps.

The following worked for me at the time of writing.
The key takeaways are:

  • You must use HTTPS in your backend. You may use a self-signed certificate.
  • To test against localhost you must create a test app from your primary app

TL;DR

  1. Make sure your server exposes an HTTPS enabled port with a self-sign certificate. Consult your server documentation.
  2. Go to https://developers.facebook.com/apps and select "Create App". Select app type that supports Facebook login (E.g. consumer), click continue
  3. Set a display name and contact email and click "Create App"
  4. Optional! When the prompt to Add Products to Your App choose Add Facebook login. Here you will set your production login setting with a real domain, but you can focus on tests app at this stage.
  5. Go to the left side of the page where your app name is displayed. In the select box and click the small arrow. When the select box expand click the button "Create Test App" enter image description here
  6. On the create test app popup select "Create Test App"
  7. On the newly created test App go to "Add a Product" and "Add Facebook login" by clicking "Set up"
  8. Ignore the setting by selecting the settings list under the "Facebook Login" on the left side of the page.
  9. Note the info message at the top "You are currently editing a test version of ..." enter image description here
  10. Verify that both Client OAuth Login and Web OAuth Login are enabled (blue yes)
  11. Under the "Valid OAuth Redirect URIs" add your local HTTPs address e.g. https://localhost:8443
  12. Click save changes.
  13. Click Setting basic on the left side of the page and copy your App Id and App Secret and keep them in a safe place

Common pitfalls

  • Make sure that you use your test app secrets when you test and not the main app, resulting in the following error

Can't load URL The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.

enter image description here

  • Make sure you use https://localhost:8443 and not https://127.0.0.1:8443 those are not the same from OAuth point of view resulting in an error similar to the one below

URL blocked This redirect failed because the redirect URI is not white-listed in the app's client OAuth settings. Make sure that the client and web OAuth logins are on and add all your app domains as valid OAuth redirect URIs.

enter image description here

1

This works for me in heroku, the localhost thing didn't work (for me). I hope it helps

1.) In the center under the first box of options, click "+ Add Platform" and choose "Website" (or whatever is appropriate for your app.)

2.) In the box that comes up for the website you just added: Site URL: http://MYAPP.herokuapp.com/ (replace MYAPP with the name of your app)

3.) In the box above that (Settings => Basic): App Domain: MYAPP.herokuapp.com (replace MYAPP with the name of your app)

4.) At the bottom right - click "Save Changes"

1

Just a note for some others who may be struggling with this as I was. I have not been able to get this to work with "test" apps. Using my actual app settings (and simply adding

"http://localhost:3000/"

to my canvas URL) worked as everyone else suggested. It seems test apps aren't equal to actual apps.

1

I ran into an issue with my Rails app that I usually run with http://localhost:3000 because Facebook now requires the Valid OAuth redirect to use https.

To use https locally, I used [ngrok][1] which allows you to use https by providing a tunnel. To do this:

  1. I went to their website and downloaded their program
  2. I extracted the file for the program
  3. In my console, I went into the directory where ngrok was extracted to and entered 'grok http 3000' on my Windows machine, others may use './grok http 3000'
  4. After entering that, ngrok provided a https address which I put into the Valid OAuth Redirect URIs field in Facebook
  5. Then I started my server and was able to access it using that https address instead of localhost:3000
1

to do local testing all you have to do is turn off the app, or put the facebook app in development mode. Then Facebook will allow you alone to access the app

0

For me it worked like this:

Configuring the facebook app dashboard:

*On the ' basic ' tab:

1) Leaving app domain empty.

2) Erasing any platform. Meaning: no website no canvas platform. (so no site-URL field to fill)

*On the 'advanced' tab:

3) I entered into the Valid OAuth redirect URIs:

http://localhost/myappfolder/redirect.php

4) regarding my code, insdie my c:/xampp/htdocs/localhost/myappfolder/index.php (this file makes the loginURL):

$helper = new FacebookRedirectLoginHelper('http://localhost/myappfolder/redirect.php');  

inside the redirect.php file:

$helper = new FacebookRedirectLoginHelper('http://localhost/myappfolder/redirect.php');  

and I got a session! finally! no need to hang myself in the end :P

0

For those still having this issue, make sure your app is in development mode while trying to use localhost as the app domain else it won't work.

0

In case you are using Hotwire, remember to use button_to instead of link_to and disable Turbo on it. E.g:

<%= button_to "Register with Facebook", user_facebook_omniauth_authorize_path, form: { "data-turbo" => "false"}, method: :post %>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.