Using this Laracast tutorial (Laravel 5.0 - Socialite), especially until 12.11, I successfully configured everything. However, I am using Laravel 5.1
Defined my route, but the callback provider currently commented, as I am just trying to get user data through the received token:
Route::get('auth/facebook', 'Auth\ AuthController@redirectToProvider '); //Route::get('auth/facebook/aaa', 'Auth\ AuthController@handleProviderCallback ');
Added essentials in config>services.php :
'facebook' => [ 'client_id' => '##', 'client_secret' => env('FB_SECRET_ID'), 'redirect' => 'http://laratest.dev/auth/facebook', ],
I decided to return to the same page ( auth/facebook ). This is why I set the return as domain.devv/auth/facebook for testing.
In my AuthController.php I installed:
public function redirectToProvider(AuthenticateUser $authenticateUser, Request $request) { return $authenticateUser->execute($request->has('code')); }
And finally, in my AuthenticateUser.php :
use Illuminate\Contracts\Auth\Guard; (PS. I changed Authenticator to Guard) class AuthenticateUser { private $users; private $socialite; private $auth; public function __construct(UserRepository $users, Socialite $socialite, Guard $auth) { $this->users = $users; $this->socialite = $socialite; $this->auth = $auth; } public function execute($hasCode) {
Now I click the Login with Facebook link and get the link to domain.dev/auth/facebook?code=943299043290...
When I use only *First dd (with all commented out lines commented out) - it returns false .
When I use only *Second dd (with the comment line $user = $this->socialite->driver('facebook')->user(); ), it returns true .
So everything works fine and goes through execute() , then through getAuthorizationFirst() . Finally, it returns to execute() with the accepted token, which is also contained in the link ( domain.dev/auth/facebook?code=943299043290... ).
My problem arises here:
The second time I will uncomment $user = $this->socialite->driver('facebook')->user(); I get an error:
ClientException in line Middleware.php 69: Client error: 400
1.in /Applications/MAMP/htdocs/laratest/vendor/guzzlehttp/guzzle/src/Middleware.php line 69
2. in Middleware :: GuzzleHttp {closure} (object (response)) in the line Promise.php 199
3. in Promise :: callHandler ('1', object (Response), array (object (promise), object (close), null)) in the line Promise.php 152
4. in Promise :: GuzzleHttp \ Promise {close} () in the line TaskQueue.php 60
5. in TaskQueue-> run () in the line CurlMultiHandler.php 96
this line ( $user = $this->socialite->driver('facebook')->user(); ) does not work for me does not work (although it works in the tutorial (min. 12.11 for a 15-second brief explanation).
Whenever I use $user = $this->socialite->driver('facebook')->user(); , I get a ClientException in Middleware.php line 69: Client error: 400 and, of course, I cannot get dd($user) .
To add, when I see a ClientException error, the link still contains the code: ( domain.dev/auth/facebook?code=943299043290... )