Problem with Oauth2 and PHP to enter with Facebook

Asked

Viewed 38 times

1

On my site I have the option to login with your Facebook account to store your creations and etc.. It always worked well after implementation, however, without any changes in data or files, everything stopped working on Thursday night. I searched for information about some new error that is occurring when doing this type of login with Oauth2 and PHP, but found nothing. I had to debug until I got as close to where the problem occurred, and there are 3 situations:

1 - Error 500 saying that the page cannot respond to the request (then I used a try-catch to solve this and find where everything stopped) 2 - Excessive redirects from both my site and Facebook (I also used the try-catch to get closer to the error) 3 - Finally, I discovered that the error occurred here:

// Aqui verifico se existe essa variável que recebo do Facebook e vem para o meu site como um parâmetro na URL, e ele realmente está vindo
if ($code) {
    $token = $facebook->getAccessToken("authorization_code", [
        "code" => $code
    ]);
    $_SESSION['userLogin'] = $facebook->getResourceOwner($token);
    header("Refresh: 0");
}

It turns out when using one var_dump in the variable $token, I get two different error messages during attempts. One says that the code that has already been used "This code has been used", or else the code has already expired "This code Authorization has expired", even if the whole process takes less than 10s in general. Also, another thing I noticed is an attribute in array which I receive in the same `var_dump, and bears the name "Expires", and is coming with the value of "Sat, 01 Jan 2000 00:00:00 GMT", as below:

 ["headers":"GuzzleHttp\Psr7\Response":private]=>
          array(16) {
            ["WWW-Authenticate"]=>
            array(1) {
              [0]=>
              string(81) "OAuth "Facebook Platform" "invalid_code" "This authorization code has been used.""
            }
            ["Content-Type"]=>
            array(1) {
              [0]=>
              string(30) "text/javascript; charset=UTF-8"
            }
            ["facebook-api-version"]=>
            array(1) {
              [0]=>
              string(4) "v6.0"
            }
            ["Strict-Transport-Security"]=>
            array(1) {
              [0]=>
              string(25) "max-age=15552000; preload"
            }
            ["Pragma"]=>
            array(1) {
              [0]=>
              string(8) "no-cache"
            }
            ["x-fb-rev"]=>
            array(1) {
              [0]=>
              string(10) "Ocultei esse valor por segurança"
            }
            ["Access-Control-Allow-Origin"]=>
            array(1) {
              [0]=>
              string(1) "*"
            }
            ["Cache-Control"]=>
            array(1) {
              [0]=>
              string(8) "no-store"
            }
            ["x-fb-trace-id"]=>
            array(1) {
              [0]=>
              string(11) "Ocultei esse valor por segurança"
            }
            ["x-fb-request-id"]=>
            array(1) {
              [0]=>
              string(23) "Ocultei esse valor por segurança"
            }
            ["Expires"]=>
            array(1) {
              [0]=>
              string(29) "Sat, 01 Jan 2000 00:00:00 GMT"
            }
            ["X-FB-Debug"]=>
            array(1) {
              [0]=>
              string(88) "Ocultei esse valor por segurança"
            }
            ["Date"]=>
            array(1) {
              [0]=>
              string(29) "Fri, 17 Jul 2020 06:10:23 GMT"
            }
            ["Alt-Svc"]=>
            array(1) {
              [0]=>
              string(43) "h3-29=":443"; ma=3600,h3-27=":443"; ma=3600"
            }
            ["Connection"]=>
            array(1) {
              [0]=>
              string(10) "keep-alive"
            }
            ["Content-Length"]=>
            array(1) {
              [0]=>
              string(3) "158"
            }
          }

Someone went through the same problem recently and managed to solve?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.