Facebook Client OAuth settings domain not working with query strings - php

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);

Related

{"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

Problem with registering webhook url on twitter app

I'm trying to register a webhook url on twitter app and I'm using this package twitteroauth.
Here's what I've code.
$cbUrl = 'https://123456.ngrok.io';
$envName = 'myDevEnvironment';
$connection = new TwitterOAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET);
$data = $connection->post('account_activity/all/' . $envName . '/webhooks', ['url' => urlencode($cbUrl)]);
I'm using ngrok to get https of my localhost webhook url. But still getting error code 214 in response and below error message.
{"errors":[{"code":214,"message":"Webhook URL does not meet the requirements. Please use HTTPS."}]}
Any help would be appreciated.
Thank you.
['url' => urlencode($cbUrl)]
Their check for whether the supplied URL starts with https:// probably fails, because you URL-encoded the value. Your package likely takes care of encoding any parameter values in API calls itself, so in this case, you would have encoded it twice now.
If they look for https:// at the start of https%3A%2F%2F123456.ngrok.io, that will fail.
Please use HTTPS..
The error is self explanitory, your requests are being denied because you are not on an secure connetcion. Install an SSL certificate on your server.
Here's the ngrok docs on Transport Layer Security
https://ngrok.com/docs#tls

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?

OAuth redirect_uri opencart by facebook sdk4

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

How to build Instagram REDIRECT URI dynamically?

i'm trying to send a get request to Instagram API, after authentication, like this
https://api.instagram.com/v1/users/self/
to get user data. It works when I set a static URL like www.WebSite.com but when
I'm trying to overwrite the REDIRECT URI that I set in my Instagram App but it gives me this error:
{"code": 400, "error_type": "OAuthException", "error_message": "Redirect URI does not match registered redirect URI"}
I'm trying to build the URL dynamically for REDIRECT URI like this:
$client->redirect_uri = home_url() . '/user-profile/'.wp_get_current_user()->ID .'/';
so please any help on how we can overwrite the REDIRECT URI. many thanks in advance for any help.
You should match the redirect URI you set in your Instagram app, pass the user id as a query parameter (e.g. ?id=1), and then get it from the $_GET array.
You can find the rules of valid URI matching in Instagram Developer Documentation

Categories