OAuth redirect_uri opencart by facebook sdk4 - php

am New to opencart 1.5.5.1 almost did all configuration to make the site have login facebook but no use.
Graph returned an error: Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request
I tried to play with url from my side nothing work as checked on internet like add slash after the link and so on
this is the requested site
https://www.facebook.com/v2.4/dialog/oauth?client_id=4444&state=444444&response_type=code&sdk=php-sdk-5.0.0&redirect_uri=http%3A%2F%2Flocalhost%2Fmarkaforyou%2Fwholesale%2F%3Froute%3Dfacebook%2Ffacebook&scope=email%2Cuser_birthday%2Cuser_location%2Cuser_hometown
this url redirected to my site
http://localhost/markaforyou/wholesale/?route=facebook%2Ffacebook&code=AQAB3eJHlzqyopMX0SSxRvChkEmoRE6LtQfghd54634645vb6ybhfgbhfghdfghjfdgh
fgZAZdYe4ivu94IsPf36hrpyfq3K4uyi7dx50&state=69e8f620cdbcdfdf43185fba9b70dc43#=
is there any thing I must need to do in configuration

it was a problem with facebook sdk url clearer
in the FacebookRedirectLoginHelper.php
change the line
$redirectUrl = FacebookUrlManipulator::removeParamsFromUrl($redirectUrl, ['state']);
with
$redirectUrl = substr($redirectUrl, 0, strpos($redirectUrl, '&state'));
and all thing work perfectly

Related

Facebook Client OAuth settings domain not working with query strings

I'm trying to get the Auth working with Facebook but it keeps on telling me that my redirect URL is not working.
In the Valid OAuth Redirect URIs I have the following
https://localhost
The issue is that, I'm passing some additional query string to my callback, like
https://localhost?uuid=something&service=my_service
When attempting to Auth, I do get the request popup and then I get a redirect URL but then Facebook is telling me that the URL is not allowed.
If I test https://localhost?uuid=something&service=my_service in Facebook's Redirect URI Validator it's telling me it's not valid
How can I add a a URL including a dynamic query string ? I've tried
https://localhost*
But Facebook is telling me this is not a valid URL and won't let me save/add this URL.
#ceejayoz put me on the right track, I will answer my own question, that might help someone else.
Additional data must be passed in a state parameter such as
$data = json_encode($some_std_class);
$pdata = $fb_helper->getPersistentDataHandler();
$pdata->set('state', $data);
$login_url = $fb_helper->getLoginUrl($my_url, $my_permissions);

{"error_type": "OAuthException", "code": 400, "error_message": "Invalid redirect_uri"}

Firstly, this is my Instagram URL after the login:
https://www.instagram.com/oauth/authorize?client_id=$MYCLİENTİD&redirect_uri=https://localhost:4000/İnstagram/Insta.php/&response_type=code&scope=user_profile,user_media
And this is the error that page shows me:
{"error_type": "OAuthException", "code": 400, "error_message": "Invalid redirect_uri"}
When I try to get user token from Instagram, I get that error.
I've tried to change the redirect_uri=(Valid OAuth Redirect URIs), but the error is the same as before.
I could not find this documented anywhere, but through trial and error, I found that the redirect_uri had to:
Use https
Be publicly accessible (e.g. localhost and specifying a port number won't work)
Not include parameters (I found they were getting stripped out, which would cause a redirect_uri mismatch when I later requested an access token)
I had the same problem and I solved it as following:
I first went here:
(remember to change your instagram app id in the below URL)
https://developers.facebook.com/apps/your_instagram_app_id/instagram-basic-display/basic-display/
Then I set my Client OAuth Settings, Deauthorize and Data Deletion Requests as "https://localhost:3000/".
That worked for me.
Actually, for me, it was because my URI was not exactly the same as requested by the app. I forgot to add "/" at the end.
Go to https://developers.facebook.com/apps/APP_ID/instagram-basic-display/basic-display/ -> Client OAuth Settings and put there not just https://localhost:5000, but exact authentication endpoint used in your application (https://localhost:5000/auth or else)
Actually, it does work with localhost, but it is very tedious.
First, you need to have https enabled (which from what I can see from your request you seem to have).
[I don't know if this is mandatory] you need to create a test app* from your main app (https://developers.facebook.com/docs/development/build-and-test/test-apps/)
Set the redirect OAuth URI to something like https://localhost:4000/auth/ and update also all other URIs in .../instagram-basic-display/basic-display/ settings.
Finally, don't forget to use the client-id(or app-id) of the test app in your request, which is different than your parent app
I wish you good luck ;)
*IMPORTANT: app-id and app-secret are different in test app!
As per documentation
Construct the Authorization Window URL below, replacing {app-id} with
your Instagram app’s ID (from the App Dashboard > Products > Instagram
Basic Display > Instagram App ID field) and {redirect-uri} with your website URL that you provided in Step 2 ("Valid OAuth Redirect URIs").
The URL must be exactly the same.
Syntax & Example as below
https://api.instagram.com/oauth/authorize?client_id=<instagram_app_id>&redirect_uri=<my-website>&scope=user_profile,user_media&response_type=code
https://api.instagram.com/oauth/authorize?client_id=00000123&redirect_uri=https://aashutosh-kumar.herokuapp.com/&scope=user_profile,user_media&response_type=code

FB Login Strict mode is not working

I am trying make a registration with FB option for my PHP based website. My callback url for the website is
http://subdomain.mydomain.com/user/fblogincb/
I have added that in the Valid OAuth redirect URIs in my Apps Facebook Login settings. The login button of my website correctly invoke the callback url, but when I try to use the access token in my call back page using the follwing code:
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}
it return the exception:
Graph returned an 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.
The redirected URL from FB is:
http://subdomain.mydomain.com/user/fblogincb/?code=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
However, turning off the Strict URLs mode does not have this issue. What am I doing wrong here for the Strict URLs mode. Any help will be appreciated.
Try and pass the exact redirect URL that was used in the login dialog call, as parameter to the getAccessToken method:
$accessToken = $helper->getAccessToken('http://subdomain.mydomain.com/user/fblogincb/');
The exact same redirect_uri parameter value must be passed in both calling the login dialog, and in the subsequent API call that exchanges the code for a token. The SDK has its own "URL detection handler" on board (or you can supply your own, in environments where custom routing logic might require that) for the purpose of determining the current URL - which usually does the job fine, but depending on the exact setup, it can fail sometimes.
I am a bit surprised by the error message, I remember seeing a different one in such cases that explicitly mentioned the redirect_uri mismatch ... but maybe while implementing strict mode something changed internally, dunno.
Do not forget to update Facebook PHP SDK to latest v5.6.2, strips code param from Facebook redirect_uri callback
Facebook SDK for PHP - changelog
5.6.2 (2018-02-15)
Strip 'code' param (#913)

OAuthException: redirect_uri isn't an absolute URI. Check RFC 3986 (Symfony)

I would like to add facebook login option to my website, following this tutorial. I did everything as it is in the tutorial, but I still get this error:
OAuthException: redirect_uri isn't an absolute URI
How is it possible to solve it?
This urls are generated by the facebookOAuthProvider. The website is not on localhost. It runs on a webserver, with https.
This is the relevant code:
// redirect to Facebook
$facebookOAuthProvider = $this->get('app.facebook_provider');
$url = $facebookOAuthProvider->getAuthorizationUrl([
// these are actually the default scopes
'scopes' => ['public_profile', 'email'],
]);
return $this->redirect($url);
It redirects to this url:
https://www.facebook.com/v2.3/dialog/oauth?scopes[0]=public_profile&scopes[1]=email&state=...&scope=public_profile,email&response_type=code&approval_prompt=auto&redirect_uri=/connect/facebook-check&client_id=...
The redirect_uri is indeed not an absolute url. But how is it possible to fix it?
Edit
If I add 'redirect_uri' => [$redir] then the url looks like this:
https://www.facebook.com/v2.3/dialog/oauth?scopes%5B0%5D=public_profile&scopes%5B1%5D=email&scopes%5B2%5D=user_location&redirect_uri%5B0%5D=https%3A%2F%2Fexample.com%2Fconnect%2Ffacebook-check&state=...&scope=public_profile%2Cemail&response_type=code&approval_prompt=auto&client_id=...
I can see the absolute redirect_uri in the generated url, but I still get this error, if I navigate to it
Redir is defined as:
$redir = $this->generateUrl('connect_facebook_check', array(), UrlGeneratorInterface::ABSOLUTE_URL);
Edit2
If I replace [$redir] with $redir then facebook redirects me correctly to /connect/facebook-check with a code, but I get a OAuthException: redirect_uri isn't an absolute URI. Check RFC 3986 there.
I don't know where you got the example code, but certainly not from the linked tutorial.
Facebook authorization is based on the fact that you generate a link to FB, the user goes to the FB and authorizes himself, and then the FB server redirects it back to you (along with whether or not it is authorized).
FB does not guess where to redirect user after login. You need to give him a full path with http(s) and the server name (and if I remember correctly, it is also compatible with that saved in the FB app)
The attached tutorial requires writing a controller with 2 methods (output and return) and corresponding entries in the configuration.
If you use this, then see how you have configured the provider. What is in redirectUri?

Login Facebook app with fb link at redirect_uri

I created a page tab app from developers so in the fields I have:
Canvas Url: http://ingersidemon.ro/proiecte/pitzi-world.ro/.facebook/concurs/
Secure Canvas Url: https://ingersidemon.ro/proiecte/pitzi-world.ro/.facebook/concurs/
Page Tab Url: http://ingersidemon.ro/proiecte/pitzi-world.ro/.facebook/concurs/
Secure Page Tab Url: https://ingersidemon.ro/proiecte/pitzi-world.ro/.facebook/concurs/
So the problem is: I want to create a login dialog something like this:
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id=".$app_id."&redirect_uri=".urlencode($my_url)."&state=".$_SESSION['state']."&scope=publish_stream";
Where $my_url = "http://www.facebook.com/1mil.Fotografii/app_415786855156952";
It gives me error because the url is not own by the application settings, but at some apps source I see this Url with facebook link working. If i set
https://ingersidemon.ro/proiecte/pitzi-world.ro/.facebook/concurs/
After the login url my app wont open in Iframe mode, it opens the https://ingersidemon.ro/proiecte/pitzi-world.ro/.facebook/concurs/ not in facebook, where I am wrong?
Yes, your app does not own http://facebook.com domain,
change $my_url to $my_url = 'http://ingersidemon.ro/proiecte/' ... where you can handle facebook response, check facebook api to see what facebook sends you back
Where $my_url = "http://www.facebook.com/1mil.Fotografii/app_415786855156952";
It gives me error because the url is not own by the application settings
Since calling that URL in my browser only leads me to the page itself (same as if https://www.facebook.com/1mil.Fotografii was called directly), I suspect you either did not install this app on the page, or you might still have sandbox mode turned on in your app settings.

Categories