0

Not a duplicate of Facebook login message: "URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings."

This issue is about CakePHP sending the wrong URL. It is fully understood why Facebook doesn't like the URL, not clear how to fix it in CakePHP


Trying to use this HybridAuth plugin for Cakephp, everything seems to be working except the redirect URL has http, which facebook does not like. I need to make it https. I cannot figure out how to manipulate this value.

https://www.facebook.com/v2.12/dialog/oauth?auth_type=rerequest...redirect_uri=http%3A%2F%2Fwww.example.com%2Fhybrid-auth%2Fendpoint%3Fhauth_done%3DFacebook&scope=email%2Cpublic_profile

Which gives me this error, which makes sense:

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.

I've been trying to fix this for about two hours. I've tried setting

'hauth_return_to' => [
                    'controller' => 'Lookings',
                    'action' => 'find',
                    'prefix' => false,
                    'plugin' => false,
                    '_ssl' => true
                ]

in the AppController authenticate settings for HybridAuth, which doesn't seem to do anything. Also tried a lot of random things around the internet that just seemed to break more things. I'm a bit lost now.

New update

I have tracked this URL's origin as far as the loginBegin method in hybridauth/Hybrid/Providers/Facebook.php, and it's in $this->params['login_done']; though I'm uncertain now where this is being set.

Old update

Updating the Appcontroller authenticate settings still doesn't seem to affect this particular URL no matter what I do. I believe this setting is related to the "URL Login done" redirect URL, and my issue is with the "URL Start login" URL, though I'm not entirely certain.

Randy Hall
  • 7,716
  • 16
  • 73
  • 151
  • Possible duplicate of [Facebook login message: "URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings."](https://stackoverflow.com/questions/37001004/facebook-login-message-url-blocked-this-redirect-failed-because-the-redirect) – Andy Hoffner Apr 17 '19 at 21:15
  • @ahoffner I understand that that is this issue, but not how to fix it within the confines of the CakePHP plugin HybridAuth. Hence being tagged with cakephp tag and not Facebook tag. – Randy Hall Apr 17 '19 at 21:38

1 Answers1

0

Add the 'base_url' property to the HybridAuth object in /config/hybridauth.php to manually set the base URL.

Additionally, it appears that base_url is create using $_SERVER['HTTPS'], which is apparently not set to true in my current environment. This can be found in the login method of the Hybrid_Provider_Adapter class.

Addressing either of those issues should fix the problem.

Randy Hall
  • 7,716
  • 16
  • 73
  • 151