artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4
685 stars 217 forks source link

Facebook Login Failed "Undefined index: access_token" #174

Open ppeinsold opened 8 years ago

ppeinsold commented 8 years ago

Hi! Sometimes I have problems with the Facebook Login. Then I get the following message:

Message: Undefined index: access_token [] [] exception 'ErrorException' with message 'Undefined index: access_token' in .../vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/Facebook.php:171 .../vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/Facebook.php(171): Illuminate\Exception\Handler->handleError(8, 'Undefined index...', '/var/www/...', 171, Array)

1 .../vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/AbstractService.php(127): OAuth\OAuth2\Service\Facebook->parseAccessTokenResponse('{"error":{"mess...')

The exception happens when I call the following function in my controller: $token = $fb->requestAccessToken( $code );

Please help. It is really anoying loosing users because login does not work sometimes! Thanks!

userhuman commented 7 years ago

I same problem. but when i print_r before get accesstoken it show error on below

vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/Facebook.php
print_r($responseBody);
exit();
parse_str($responseBody, $data);

"message":"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"

Please help me.

Gummibeer commented 7 years ago

@userhuman The error message tells you exactly what you have to do. Every Facebook App has allowed Domains for API calls - you have to enter all domains you are using for API calls and after this it should work.

userhuman commented 7 years ago

@Gummibeer I so many try to do. I call every link is related but it's not work.

One month before it's work. but now I checked it can not login with facebook.

You have anyway for fix it. I will thank you so much.

userhuman commented 7 years ago

Now it work. Thank

alexescg commented 7 years ago

@peiphb02 This issue was resolved in lusitanian/oauth dependency. The problem was that in the previous version, the lib was using parse_str($in, $out); The fix made was to use json_decode. A fork I made has the new version, you can use it yourself by editing your composer.json:

"require": {
     //...
    "artdarek/oauth-4-laravel": "dev-master as dev-lusitanianversion"
  },

 "respositories": [
    {
      "type": "vcs",
      "url": "https://github.com/alexescg/oauth-4-laravel"
    }
  ]

You can then install it by using composer update --with-dependencies

arifw3 commented 7 years ago

Thanks.I installl by using composer update its run on laravel 4.2

nenads commented 7 years ago

@artdarek can we have this merged on repo ?

jbruni commented 7 years ago

Thanks @artdarek - I've seen you merged @alexescg update.

For those like me arriving here with the issue, here is how I updated my app:

    "artdarek/oauth-4-laravel": "dev-master@dev",
composer update artdarek/oauth-4-laravel --ignore-platform-reqs --with-dependencies

The important snippet is --with-dependencies. The --ignore-platform-reqs was necessary for me due to other configurations.

radavel commented 6 years ago

Hello you need to change the line 162 in the follow file vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/Facebook.php:

parse_str($responseBody, $data);

To this one:

$data = json_decode($responseBody, true);

This work's for me!!