I'am developing android application with facebook login and laravel REST API server. After user login on mobile, app get token which is sent to my server. On server I want get facebook user details by token.
Facebook SDK for PHP provides methods for that:
$session = new FacebookSession('token');
$me = (new FacebookRequest($session, 'GET', '/me',))->execute()->getGraphObject(GraphUser::className());
Can Laravel Socialite obtain user facebook details based on that token? Or just use that Facebook SDK?
You can also extend your Socialite Facebook Provider.
For example;
Create a class as SocialConnect in App/Library folder
Then add these lines in boot method on your App/Providers/AppServiceProvider.php
Ready for use!
You can also add new methods as you wish in your SocialConnect class.
There is a method
getUserByToken
implemented in the Facebook Service Provider, however it'sprotected
and only used internally to get theuser
details.So you're better off using the Facebook SDK.
I submitted a pull request to the repo which was accepted to the 2.o branch. You should be able to call
Socialte::driver('facebook')->userFromToken($token)
now.https://github.com/laravel/socialite/pull/126
Cheers.