facebook app: cross domain error although it seems well set-up - facebook

I have a web app that runs on localhost or example.com. And I am loading the facebook apps sdk to be able to do Single Sign-On, but I have this error in the console:
XMLHttpRequest cannot load https://www.facebook.com/impression.php. No 'Access-Control-
Allow-Origin' header is present on the requested resource. Origin
'http://example.com' is therefore not allowed access.
whereas I have gone in the settings of the facebook app and enter http://localhost/ or http://example.com/ in the Site URL field.
Here's the screen capture of my local url for instance :
...and the corresponding setting my facebook app account :
I really need some help here please !

Url given in SITE URL field must be match with your WEB URL [where facebook sdk invoked.]
Hence in your case, SITE URL field given : www.example.com
Web App URL must be : www.example.com

I'm running it locally under IIS Express using
http://localhost:XXXXX/
where XXXXX is the port number the website is running on and that works for me.

Related

“URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings.” But works locally

I have problem like here Facebook login message: "URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings."
I have checked various answers - cant make it work, and they don't give much new - just practically say to add url to that field.
One of them said to "Make sure your App IDs and Secret Keys are correct."
I found out they were not set, but now admin said he added those so should be ok.
What else to do? How to debug?
"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."
It also tells to check Client and Web OAuth to make on, but I have them off to increase security becasue I have read or watched somewhere in facebook documentation. And since login works locally with them turned off, they should be not be needed. I tested by trying to turn them on, but as I expected they don't fix the problem.
Update:
Redirect uri parameter is redirect_uri=https%3A%2F%2Falpha.vop.veracityinsurance.com%2Fconnect%2Ffacebook%2Fcheck
Made a video: https://www.loom.com/share/88e607aece6b45489214d95ee01bbb0b
I have made debug function and pushed it to server which prints provider:
$provider = (array)$this->clientRegistry->getClient('facebook_main')->getOAuth2Provider();
print_r($provider);
And from that class I see app id is correct in server.
config.yml
knpu_oauth2_client:
clients:
# the key "facebook_main" can be anything, it
# will create a service: "knpu.oauth2.client.facebook_main"
facebook_main:
# this will be one of the supported types
type: facebook
client_id: '%env(CONFIG__OAUTH__FACEBOOK__ID)%'
client_secret: '%env(CONFIG__OAUTH__FACEBOOK__SECRET)%'
# the route that you're redirected to after
redirect_route: connect_facebook_check
redirect_params: {}
graph_api_version: v5.0
Btw I am using symfony bundle for integration https://github.com/knpuniversity/oauth2-client-bundle
Made it work as 04FS said to turn on settings. It was enought to turn on one of them only - Web OAuth Login.

Using Facebook & Twitter API's on the same local deployment

I am trying to build an application on my local machine using Twitter's OAuth 1.1 API and Facebooks SDK v4 both for PHP.
Both of these mechanisms redirect the user to prompt for permission and redirect back to website. I can get both working but they will not work under the same local url.
I set everything up for Facebook on localhost without any issues but twitter (staggeringly) does not allow using localhost (see here How to test the twitter API locally?). So instead I set up a virtual host using my Mac based MAMP installation and added that url to both Twitter and Facebook applications. Now Facebook does not allow me to use my virtual host. When the prompt for permissions happens and Facebook redirects back to my site, when I try and retrieve the session using getSessionFromRedirect() it returns NULL. This does not happen if I run the same code using localhost.
I have tried using 127.0.0.1 but Facebook does not allow this either (error is invalid because it is a Facebook url!), but Twitter does!?!
Has anyone else had any problems with this or does anyone have any pointers that would help me to test both of these on the same deployment.
Many thanks in advance.

GWT - development mode - Facebook - Access Token - redirect_uri

I'm developing a website that is going to use Facebook authentication.
I'm using GWT and it works fine when I run the code compiled, but when I'm running the development it does not work.
The problem is when I'm trying to retrieve the access_token from Facebook.
I'm receiving the error below:
"error":{"message":"Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request","type":"OAuthException","code":100}"
Obviously, the redirect_uri is identical as the login url one.
I found out (by this topic) that the problem is the last part of the url "?gwt.codesvr=127.0.0.1:9997".
How can I solve this? or how can I manage to use the GWT development mode with this problem?
Thanks,
Normally this is due to the url verification FB does.
When you register a new app in FB you have to configure the set of domains (App Domains) authorized to use the FB login form.
Unfortunately you cannot set 127.0.0.1 nor localhost as a valid domain, so you cannot use GWT dev-mode unless you configure a hostname in your domain pointing to your localhost.
If you set mydomain.com as a valid App Domain in your FB application, configure localhost.mydomain.com pointing to 127.0.0.1 in your local hosts file or in your DNS server. Then use http://localhost.mydomain.com:8888/myapp.html?gwt.codesvr=localhost.mydomain.com:9997 to run dev mode in your browser.
I found out the problem.
By encoding only the gwt.codesvr value it works.
However, using php urlencode function on it did not work, I had to encode it myself.
The gwt dev param ended like this "?gwt.codesvr=127.0.0.1%3A9997"

Facebook error code 191

I've scoured SO and googed all over the place, and I'm still stuck. I feel a little ridiculous, but I've been banging my head against this wall for a few hours.
Here are my FB app settings:
App Domain: name.local
Site URL: http://name.local:4000
I'm running a local web server and have a web application up and running.
Authentication works (which seems odd because my redirect_url is the same in both the authentication URL and the dialog/feed URL)
name.local is in my /etc/hosts file and points to 127.0.0.1.
I'm running on port 4000.
This URL doesn't work:
https://www.facebook.com/dialog/feed?client_id=nnnnnn&redirect_uri=http%3A%2F%2Fname.local%3A4000&name=aname&caption=acaption&description=descr&show_error=true
I get this error message:
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: redirect_uri is not owned by the application.
I'm using test users (created using the FB test user API).
I've checked that my Site URL and redirect URL are in unison about a million times.
Any idea what I'm doing wrong?
Site url and app url must be shame .
app url should not contain protocol information .
site url should contain protocol
I love computers, they do exactly what you tell them to :)
I had to use app_id instead of client_id (that's what I get for copying and pasting from my authorization code).

Facebook Connection Failed error in magento website?

I have done following steps:-
created an facebook App with all the details filled and got AppID and App Secret.
Integrated an facebook extension to my magento website and filled AppID and App Secret to magento admin.
When I login then it asks for the permissions to access the facebook user details also, but after that it shows error "Facebook Connection Failed".
My website is at localhost and I filled site url = "http://localhost/magento/mywebsite.php" in the facebook App which I created.
I have done this thing prior also. It worked previously but not working this time.
You can't use localhost URLs when configuring your app. The URL needs to be accessible to Facebook. Either use the IP address of your test server, or register a test domain.