Search code examples
phplaravelfacebooklaravel-socialitedingo-api

Facebook Socialite get user from token and secret


In laravel docs there is a part about getting user from using ->userFromTokenAndSecret however it seems to be not working with facebook and returns an error that this method doesn't exist.

How do I get the user by token and secret?

I'm using Laravel as API so that it works stateless and I don't use any redirects.
I sign in using Angular app and send token then. I need to process that.


Solution

  • I've found an answer to my questions and it is userFromToken. What is the idea:

    1) I authorize my user on Angular 6 using ngx-social-login

    2) I receive user data from Facebook

    3) I send authToken to the API

    4) I receive user data from Facebook on my backend API using Socialite::driver('facebook')->stateless()->userFromToken($token)

    5) Do any stuff what I want. In my case I save data to DB or retrieve user if exists and then create a token for that user using JWT and return it