Application authentication stuck in an infinite redirect loop

My application is stuck in an infinite redirect loop because $ facebook-> getUser (); always returns 0. I read a lot of threads here on stackoverflow and other sites, as well as about similar problems, but no solution has yet been found. For authentication, I use the following code:

// $facebook = new Facebook(array( 'appId' => APP_ID, 'secret' => APP_SECRET, 'cookie' => true, )); // Get User ID $user = $facebook->getUser(); if ($user) { try { // Proceed knowing you have a logged in user who authenticated. $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); $user = null; } } // Login or logout url will be needed depending on current user state. if ($user) { $logoutUrl = $facebook->getLogoutUrl(); } else { $loginUrl = $facebook->getLoginUrl( array ( "scope" => "user_likes,email,user_hometown,publish_stream", "redirect_uri" => "https://www.facebook.com/pages/erdekelnehu/268142359907805?sk=app_175080802604575" )); die ('<script type="text/javascript">top.location.href="' . $loginUrl . '";</script>'); } 

After some debugging, I found that, being redirected from the oauth dialog, my application does not have a signed_request file. $ _GET, $ _POST and $ _REQUEST are all empty arrays. $ facebook-> getLoginUrl returns the following URL: https://www.facebook.com/dialog/oauth?client_id=175080802604575&redirect_uri=https%3A%2F%2Fwww.facebook.com%2Fpages%2Ferdekelnehu %2F26814235038078056075175780178017801780780580751757757780f2aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = user_likes% 2Cemail% 2Cuser_hometown% 2Cpublish_stream

I tried calling $ facebook-> getLoginUrl without the redirect_uri parameter, leaving it fb to figure out the correct return url: https://www.facebook.com/dialog/oauth?client_id=175080802604575&redirect_uri=https%3A%2F%2Ferdekelne. hu% 2Fdroidtv% 2F & state = 3c0d5802c89e913368ea814d49792454 & scope = user_likes% 2Cemail% 2Cuser_hometown% 2Cpublish_stream

The two URLs do not match and no one works. The second URL is redirected to the fb error page, which says that some error has occurred, and "We are working to fix this as soon as possible." So can this be a fb error, or am I doing something wrong? Any ideas will be appreciated, after 6 hours of debugging, I completely exhausted them.

+4
source share
1 answer

A similar problem just appeared, and it was fixed by updating the spaces in the directory name (where the application was placed) in URL-compatible characters, i.e. %twenty. It worked like a charm.

0
source

Source: https://habr.com/ru/post/1397020/


All Articles