Facebook OAuth "The domain of this URL isn't included in the app's domain"
Asked Answered
B

31

327

Let me first start with saying I've searched for an answer to this question for quite some time...

I'm trying to setup Facebook OAuth to work with my application that is being developed locally on my machine. Everything was working perfect with Facebook authorization UNTIL I moved from using localhost to another domain name (still local to my machine.) Now I'm getting 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 subdomains of your app to the App Domains field in your app settings.

My hosts file contains 127.0.0.1 domain.dev (works perfect)

My redirect in my app (using Socialite) is http://domain.dev/auth/facebook/callback

In my Facebook App Settings...

  • my App Domain is domain.dev
  • my Site URL is http://domain.dev/
  • my Valid OAuth redirect URIs is http://domain.dev/auth/facebook/callback

The URL at the time of the error message is..

https://www.facebook.com/v2.5/dialog/oauth?client_id=XXXXXXXXXXXXXXX&redirect_uri=http%3A%2F%2Fdomain.dev%2Fauth%2Ffacebook%2Fcallback&scope=email&response_type=code&state=0ztcKhmWwFLtj72TWE8uOKTcf65JmePtG95MZLDD

I'm at a loss of what the problem is...

Screen Shot 1
Screen Shot

Screen Shot 2 enter image description here

Betrothal answered 6/5, 2016 at 3:22 Comment(6)
Hi dangel, you might want to obfuscate your FB client_id from this postPincus
@dangel how you solved this issue??i am having same issue ,but not able to solve.Forty
@Ghimire, in my situation, I had changed the URL and didn't update my client\secret. From reading the solutions below, it looks like there could actually be various different reasons all giving the same error.Betrothal
@dangel check this .#46627414Forty
If you've solved your problem please share your solution.Hypothecate
So facebook cannot be like "Hmm your OAuth redirect URIs is not correct or empty". What the hell?Crymotherapy
B
98

This usually happens if you have entered the wrong details when you created the App in Facebook. Or have you changed a URL's of an existing App?

Can you please recheck the settings of your APP in this page?

https://developers.facebook.com/apps

  1. Select the correct App and click the edit button;

  2. Check the URLs & paths are correctly entered and are pointing to the site where you have installed Ultimate Facebook plugin.

Borneol answered 6/5, 2016 at 14:55 Comment(6)
I just now saw what you said about "you changed a URL's of an existing App" that's exactly what happened, and I guess it caused a new client\secret ID to be generatedBetrothal
Hi, I am also trying to implement fb oauth in my app. I have give all details on fb app. But, following error will appear while callback redirect. InternalOAuthError: Failed to obtain access token at Strategy.OAuth2Strategy._createOAuthError (D:\node_tutorials\fb\node_modules\passport-oauth2\lib\strategy.js:370:17) at D:\node_tutorials\fb\node_modules\passport-oauth2\lib\strategy.js:166:45 at D:\node_tutorials\fb\node_modules\oauth\lib\oauth2.js:177:18Vehemence
Another thing to try that worked for me: try switching your callbacks from https to http. That involves changing both the code that calls getLoginUrl() as well as changing the callback URLs in the app settings. The callbacks never worked with HTTPS for me, for some reason, despite the site using HTTPS.Pendent
I have same issue, but upon opening the page locally; I added 127.0.0.1:8000 to the authorized addresses, as it is how my easyphp installation is configured, but it still does not work. Can I only test FB scripts online?!?Stanza
"click in the edit button" ummm which button is that?Pandemonium
Besides having the "app domains" in two different locations without much information (3 if you add a "web" platform), you also need to go to app products / facebook login / settings and add your redirect URL under Valid OAuth Redirect URIsDonettedoney
F
259

In case someone comes across this and is looking for these settings (like I was)

You have to

  1. On the left hand side, click "+Add Product" and select "Facebook Login" (it was at the top for me)
  2. See the new settings available on the left hand side
  3. You will now have these OAuth settings on that "Product Settings"

enter image description here

Additional Info: Make sure to add the Callback URL like http://localhost:3000 to the Valid OAuth redirect URIs field on the settings page of Facebook Login

Fishing answered 13/5, 2016 at 1:51 Comment(9)
This is not what the error message refers to. There is a specific error message regarding Valid OAuth redirect URIs, which is not what is happening here. The message clearly refers to Settings » Basic » App Domains. However, the problem is that even though the correct domains are filled in, the error message still appears.Nepil
@HakamFostok urban dictionary aside, Maths reigns in higher order for the meaning of LHS/ RHS en.wikipedia.org/wiki/Sides_of_an_equation, especially in the world of coding.Fishing
This fixed it for me. Even though I had the domain filled in correctly I had not added a redirect url. Adding the redirect URL fixed the issue. Looks like at the moment FB are sending the wrong error message for this issue.Mulligrubs
i'm working locally and this is my url 127.0.0.1/CM/public what should be my Valid OAuth redirect URI ?Hexapla
@YoussefBoudaya it would be the same, 127.0.0.1/CM/public the same as the localhost exampleFishing
t tried that but i get this error "can't load url the domain of this url isn't included in the app's domains" and this is the redirect uri i found in the facebook login dialog "&redirect_uri=http%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter%2Fr%2Fnj6HSwERpgK.js%3Fversion%3D42%23cb%3Df884c7929ff818%26domain%3D127.0.0.1%26origin%3Dhttp%253A%252F%252F127.0.0.1%252Ff1d77e19e92c75c%26relation%3Dopener%26frame%3Df3ef56bf37b9618"Hexapla
This worked for me in api v2.7 and @RichardGarside's comment is accurate. I had no value set for Valid OAuth Redirect URIs and adding this field value resolved the bad FB error message relating to updating your App Domains.Tenebrae
I can also confirm that adding the redirect_uri solved the problem, even though the error message says to update the app domains. The error message is wrong in this case and misleads you.Weintrob
The additional info did it for me too :). Facebook should improve this error message.Inductor
B
98

This usually happens if you have entered the wrong details when you created the App in Facebook. Or have you changed a URL's of an existing App?

Can you please recheck the settings of your APP in this page?

https://developers.facebook.com/apps

  1. Select the correct App and click the edit button;

  2. Check the URLs & paths are correctly entered and are pointing to the site where you have installed Ultimate Facebook plugin.

Borneol answered 6/5, 2016 at 14:55 Comment(6)
I just now saw what you said about "you changed a URL's of an existing App" that's exactly what happened, and I guess it caused a new client\secret ID to be generatedBetrothal
Hi, I am also trying to implement fb oauth in my app. I have give all details on fb app. But, following error will appear while callback redirect. InternalOAuthError: Failed to obtain access token at Strategy.OAuth2Strategy._createOAuthError (D:\node_tutorials\fb\node_modules\passport-oauth2\lib\strategy.js:370:17) at D:\node_tutorials\fb\node_modules\passport-oauth2\lib\strategy.js:166:45 at D:\node_tutorials\fb\node_modules\oauth\lib\oauth2.js:177:18Vehemence
Another thing to try that worked for me: try switching your callbacks from https to http. That involves changing both the code that calls getLoginUrl() as well as changing the callback URLs in the app settings. The callbacks never worked with HTTPS for me, for some reason, despite the site using HTTPS.Pendent
I have same issue, but upon opening the page locally; I added 127.0.0.1:8000 to the authorized addresses, as it is how my easyphp installation is configured, but it still does not work. Can I only test FB scripts online?!?Stanza
"click in the edit button" ummm which button is that?Pandemonium
Besides having the "app domains" in two different locations without much information (3 if you add a "web" platform), you also need to go to app products / facebook login / settings and add your redirect URL under Valid OAuth Redirect URIsDonettedoney
E
69

I had the same problem. I solved it by adding my OAuth redirect URI as a argument to the getAccessToken function call:

$redirectLoginHelper->getAccessToken("https://www.example.com/myfacebookcallback")

If no argument is sent into that function the SDK generates the redirect URI by itself which should work but in my case it didn't.

Hope this helps someone.

Entertainer answered 20/8, 2016 at 8:8 Comment(4)
In my case, the url itself should not include empty parameters. When I give "www.example.com?param" to getAccessToken, FB always said it doesn't match URI I gave to getLoginUrl, which I'm absolutely sure is exactly the same. Using "www.example.com" doesn't rise such error.Chesterton
i'm working with javascript SDK where should i add the redirect url ?Hexapla
url i provided was getAccessToken('sitename.com/callback/facebook')Denotation
Just wanted to mention that in 2023, this is still the solution for me. This parameter must be set, even after the redirect has taken place and you're simply verifying the access token. When getAccessToken is empty, Facebook throws an error like this: "Unable to load URL: The domain name of this URL does not contain the domain name of the application. To be able to load URLs, add all domains and subdomains of your application in the Application domain name field of the application settings." (except the error was in Chinese, which was even more unhelpful).Prom
W
42

Make sure your app is public. Click on + Add product Now go to products => Facebook Login Now do the following:

Valid OAuth redirect URIs : example.com/

Deauthorize Callback URL : https://example.com/facebookapp http://unicodeitsolutions.com/

Weatherspoon answered 26/2, 2017 at 13:55 Comment(2)
What is the Deauthorize Callback URL : https://example.com/facebookapp needed for? Will it work without that?Dispirited
Deauthorize Callback URL is not mandatory ... when user will deauthorize our app , facebook will ping us by the url.Weatherspoon
K
34

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 subdomains of your app to the App Domains field in your app settings.

I had this issue today, I find the Facebook documentation and SDK disrespectful and arogant towards other developers to say the least.

Besides having the "app domains" in two different locations without much information (3 if you add a "web" platform), you also need to go to app products / facebook login / settings and add your redirect URL under Valid OAuth Redirect URIs

The error says NOTHING about the oauth settings.

Kingsley answered 17/7, 2018 at 21:38 Comment(3)
Yes, I had to do this extra step too. I share your views on the documentation!Swarth
Exactly. Looking on the valid doains and everything was right. After tens of minutes I open the login section and see redirect url again and it is empty. It is against all standards to have the same thing on two places. But what to expects from Facebook.Donettedoney
You just save my life!Cabriole
D
26

Here's what I did to solve this issue: enter image description here

Basically:

1) Enable "Embedded Browser OAuth Login"

2) Disable "Use Strict Mode for Redirect URIs" and enter a redirect URI like the way I did.

3) Leave all the rest of the options as they are.

4) Save your changes.

5) Enjoy :)

Denunciate answered 27/10, 2017 at 20:25 Comment(3)
This solved it for me. I did not want to take my app public as I was only doing a tutorial and testing it locally. Thank you @bangbangChervonets
For me, Use Strict Mode for Redirect URIs cannot be disabled.Dirigible
After 2019 strict mode can not be disabled, this solutions won´t work anymoreThicken
D
17

Facebook has recently disabled the toggle button for 'Use Strict Mode for Redirect URIs', so you need to add exact URI what's being called when you hit login button. For my case it was as shown in screenshot. It solved the issue for me :)

enter image description here

Deadradeadweight answered 2/5, 2018 at 15:56 Comment(0)
C
10

I had the same problem, and it came from a wrong client_id / Facebook App ID.

Did you switch your Facebook app to "public" or "online ? When you do so, Facebook creates a new app with a new App ID.

You can compare the "client_id" parameter value in the url with the one in your Facebook dashboard.

Cosimo answered 6/5, 2016 at 15:53 Comment(3)
All I did was change the domain and site URL to correspond from changing from localhost to photovote.dev. I updated the redirect URI on my App and also in the Facebook settings. I might just try creating a new appBetrothal
hmm, I guess I changed something on the app settings that caused a new ID to be generated, because you're right it wasn't matching anymore. Perhaps when I updated the site URL? regardless it's working againBetrothal
This worked for me. Was using an old app id in production.Koffler
J
10

In my case, things i had to do is only enabling the Embedded Browser OAuth Login

enter image description here

Jakejakes answered 14/8, 2018 at 17:25 Comment(2)
I was also using the browser based login, so the same problem I was facing. Also there is an input box below where I had to put my exact redirect URI.Confide
Besides having the "app domains" in two different locations without much information (3 if you add a "web" platform), you also need to go to app products / facebook login / settings and add your redirect URL under Valid OAuth Redirect URIsDonettedoney
P
9

As of 2017-10.

Solution that solved my issue.

Currently that FB renders this surprise.

...app’s Client OAuth Settings. Make sure Client and Web OAuth Login are on...

enter image description here

The settings to adjust are located here https://developers.facebook.com/apps/[your_app_itentifier]/fb-login/.

The trailing slash is important. They must match in your app code and in FB admin settings. So this is a config somewhere in your code (see below how to get any domain name for a dev app):

{
    callbackURL: `http://my_local_app.com:3000/callback/`, // trailing slash
}

and here

enter image description here

To get any domain name for an app on a local Windows machine, edit host file. Custom names are good in order to get rid of all those localhost:8080, 0.0.0.0:30303, 127.0.0.0:8000, so forth. Because some third party services like FB sometimes fail to let you use 127.0.0.0 names.

On Windows 10 hosts file is here:

C:\Windows\System32\drivers\etc\hosts

Backup initial file, create a copy with different name (Doesn't work in native Windows CMD. I use Git for Windows, it has many Unix commands)

$ cp hosts hosts.bak

Add this in hosts

127.0.0.1  myfbapp.com # you can access it in a browser http://myfbapp.com:3000
127.0.0.1  www.myotherapp.io # In a browser http://www.myotherapp.io:2020

In order to get rid of port part :3000 set up NGINX, for example.

Pawnshop answered 25/10, 2017 at 12:41 Comment(3)
Thanks for this, had no idea the trailing slash was required!Kassala
in May 11 2018, callback url on apps and valid oauth redirect URIs at facebook must be same. and https is must though.Percussive
Trailing slash saves my time. Thanks!Agriculturist
G
9

Most of the time its happen with not insert proper valid OAuth redirect URL in the product section of the FB dashboard.I suggest follow my bellow steps

01.Check the basic setting of the app is okay with bellow picture with you

enter image description here

02.check whether you have add a product

If not you can easily add log in product by clicking + sine as I show in the bellow.

If Yes just got to inside of the product setting. enter image description here

03.The check whether you have provide valid OAuth redirect URL

Its simple mean what should after login.It is not other than that your call back URl.You can see in my bellow picture I have added several redirect URLs. enter image description here

  1. have any problem further Watch my video-- > https://www.youtube.com/watch?v=mdhubrzV5y8&t=3s
Gargantuan answered 15/3, 2018 at 17:34 Comment(1)
2 year old question, and links to external sites should not be the primary content of an answer.Letters
M
8

The way I fixed it: I went to the Valid OAuth Redirect URIs textbox and set the exact URL, not just the domain:

before: https://my-website.com

after: https://my-website.com/facebookoauth/facebooklogin

(the url may be different in your case, check it in the address bar of the browser).

This was caused by the setting Use Strict Mode for Redirect URIs, which was locked in the Yes position.

Mesoderm answered 24/4, 2018 at 8:56 Comment(0)
F
6

Click here Code Project! Its Code project example. Its working to me

enter image description here

Fifty answered 3/11, 2017 at 7:19 Comment(0)
P
5

I had the same problem,

I just added the link of my local adress http://localhost/Facebook%20Login%20Test.html to Site URL in my application setting https://developers.facebook.com/apps.

Now it works fine :) I hope this was useful ;)

Perea answered 26/7, 2016 at 1:11 Comment(0)
M
4

Nothing really worked for me, until I updated the SDK version I was using. I started with 5.0. Not even 5.4.0 would not work either. When I updated to 5.6.2, it worked flawlessly, despite there being nothing in the changelogs that was relevant!

Moonstruck answered 23/3, 2018 at 4:31 Comment(1)
I exactly had this problem! I was using "5.4.2" and upgraded to "5.6.2"Ineptitude
K
3

This option should be enabled in portal:

enter image description here

Kamat answered 5/7, 2017 at 4:44 Comment(2)
Thanks. I had the same problem and this was the switch I missed.Ensign
Thanks! This also worked for me (I was using Google Firebase. I also had to set the "Valid OAuth redirect URIs" to the OAuth redirect URI given to me by google for my project.)Morganne
C
2

In case this helps anyone else, this started happening for me on an older site when "Valid OAuth Redirect URIs" became mandatory. The site was still using the V4 PHP SDK and the problem was resolved for me by upgrading to the V5 SDK.

Chaussure answered 23/3, 2018 at 16:11 Comment(0)
W
1

In the App domain section, you are writing your app domain but you also need to add your login domain i.e. the name of html page where you ask user to login. In my case, I was testing it on localhost and the login route was localhost/login, If I only put http://localhost.com in App domain section, I get this error. But after adding http://localhost/login.com, the error was fixed. and also the App settings has changed in newer version of SDK, in which there is no option for OAuth redirect route. You've to assign the redirect route directly from server side, after successfully getting OAuth token.

Warchaw answered 19/6, 2017 at 22:40 Comment(0)
W
1

This worked for me:

Here's the main thing to understand: Facebook will always check for the "WWW" domain. So make sure www.your_domain.dev is working on your browser first.

It is possible that if you have multiple virtual hosts on your local server, some other virtual host overrides "www.your_domain.dev". So please check that. Apache will pick the FIRST definition of domain (or ports, or something in these terms - I'm no expert on this, but learned by mistakes). An easy quick fix for this virtual host overriding is to put "www.your_domain.dev virtual host definition on the very top of the file "httpd-vhosts.conf".

Go to "/apache/conf/https-vhosts.conf" and put this on the very top of the file:

<VirtualHost *:80>
<Directory "C:/your_app_folder_path/">
    Options FollowSymLinks Indexes
    AllowOverride All
    Order deny,allow
    allow from All
</Directory>
ServerName your_domain.dev
ServerAlias your_domain.dev
DocumentRoot "C:/your_app_folder_path/"
</VirtualHost>

###### FOR SSL #####
<VirtualHost *:443>
    DocumentRoot "C:/your_app_folder_path/"
    ServerName your_domain.dev
    ServerAlias www.your_domain.dev
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:/your_app_folder_path/">
        Options All
        AllowOverride All
        Require all granted 
    </Directory>
</VirtualHost>

Next: If you are using Windows system, edit your "hosts" file in "C:\Windows\System32\drivers\etc" by adding two lines:

127.0.0.1 your_domain.dev
127.0.0.1 www.your_domain.dev

Next: Restart your Apache server and everything should work now.


I hope this will help you and save your time. I wasted almost a whole day searching around the web and was pulling my hair out and couldn't find anything helpful until I found this.

Walking answered 6/10, 2017 at 7:52 Comment(0)
D
1

The problem, and the answers, keep changing as FB tightens up the login procedure. Today, I started getting this horror message "The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings."

The answer was: now FB wants the full redirect uri. So for me, where it used to be just https://www.example.com it now wants https://www.example.com/auth/facebook/callback. This has to go in the "Valid OAuth redirect URIs" field (Developer/Facebook login->setting)

Dingbat answered 17/3, 2018 at 0:14 Comment(0)
R
1

Facebook Login -> Settings -> Valid OAuth redirect URIs -> insert the domains of your redirect url, remember you should add 'https' or http. eg: if your redirect url is https://xxx.xxx.com/path/callback.do, you only need to enter https://xxx.xxx.com/, it's ok for me.

Ray answered 20/3, 2018 at 9:31 Comment(0)
K
1

I had the same problem.....the issu is in the version PHP SDK 5.6.2 and the fix was editing the following file:

facebook\src\Facebook\Helpers\FacebookRedirectLoginHelper.php

change this line

$redirectUrl = FacebookUrlManipulator::removeParamsFromUrl($redirectUrl,['state','code']);

to

$redirectUrl = FacebookUrlManipulator::removeParamsFromUrl($redirectUrl,['state','code','enforce_https']);

Klinges answered 18/11, 2018 at 22:32 Comment(0)
I
0

This same Facebook error happened to me in the Production environment. The reason was I had 2 apps registered with Facebook (Local, Production) but I hardcoded the Local app ID into the source code and forgot to switch it out for the Production app ID before deployment.

Best practice dictates you shouldn't have the app ID hardcoded into the source code but if you do, do not mismatch your various Facebook app IDs like I mistakenly did.

Intercept answered 28/11, 2017 at 16:15 Comment(0)
K
0

Using my own local server.

Simply adding http://localhost/my-site as a URL in:

https://developers.facebook.com/apps/YOUR-APP-ID/fb-login/

worked for me.

Kerikeriann answered 9/12, 2017 at 13:48 Comment(0)
A
0

first step: use all https://example.in or ssl certificate URL , dont use http://example.in

second step: faceboook application setting->basic setting->add your domain or subdomain

third step: faceboook application login setting->Valid OAuth Redirect URIs->add your all redirect url after login

fourth step: faceboook application setting->advance setting->Domain Manager->add your domain name

do all this step then use your application id, application version ,app secret for setup

Amourpropre answered 24/4, 2018 at 9:23 Comment(0)
B
0

on Magento 2 Social Login extension, you have to copy Valid OAuth redirect URIs from the panel and add the link to Valid OAuth Redirect URIs field in Client OAuth Settings page at developers.facebook.com

Berkow answered 12/12, 2019 at 11:57 Comment(0)
H
0

If your game has no server/site (e.g. if you develop for Gameroom like me) - add "https://apps.facebook.com/xxxxxxxxxxxxxxxxx" (put your app ID instead of "xxxxxxxxxxxx") to "Valid OAuth Redirect URIs".

Hypnotherapy answered 16/12, 2019 at 19:26 Comment(0)
F
0

in my case, i solved this issue by adding the full URL and not only the domain as facebook ask. i hope that they will rename it for more clarification. so the Valid OAuth Redirect URIs should be like so:
Before: https://www.mobile-battles.com
After: https://www.mobile-battles.com/register

Freon answered 14/2, 2021 at 2:49 Comment(0)
L
0

The Meta for Developers interface currently provides two places where you can enter the domains for your app: the Basic settings under "App domains", and the Advanced settings under "Domain Manager". The SDK might not recognize your domain if it is listed in just the Domain Manager.

Lester answered 9/2, 2022 at 12:43 Comment(0)
I
0

If you are using AWS Cognito then add the URL https://<your-user-pool-domain>/oauth2/idpresponse to the Valid OAuth Redirect URIs in Facebook Login -> Settings

Infest answered 20/10, 2022 at 7:12 Comment(0)
G
0

I read through maybe every answer on the internet and nothing worked in my case.

I kept getting this error:

JSSDK Unknown Host domain The Domain you are hosting the Facebook Javascript SDK is not in your app's Javascript SDK host domain list. Please specify your host domain in App dashboard login settings.

But in the end, I found a solution. By the time of writing this (late October 2022) the fix in my case was this:

  1. Go to https://developers.facebook.com/apps/your-app-id-here/fb-login/settings - note: this url might change in the future. Just go to your developer's app -> Products -> Facebook Login -> Settings
  2. Search for Allowed Domains for the JavaScript SDK
  3. I had my url written in this way: https://www.website.com/. After I added the non-www version everything worked out! https://website.com/

Hope this fixes the issue for somebody else too!

Gluttonize answered 27/10, 2022 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.