I'm trying to use Laravel Socialite package over an api. I try to pass the code into my api to fetch the user but it keeps giving me an error:
Fatal error: Call to a member function pull() on null
Since I'm doing the request over an API, I take the following steps.
Send a request to api for the url to fetch the code:
Socialite::with('facebook')->stateless()->redirect()->getTargetUrl()
Then make a request with the above fetched url, which redirects with the code
parameter.
Send the code to the api and fetch the user:
$fb_user = Socialite::with('facebook')->user();
This is where it crashes. I'm not sure why.
I've used the package before and it works fine when I just have an app that reloads the page. But when I send it to an api (on a different domain) it crashes. I'm thinking there is some issue with how the code is generated. Is there anyway to fix this?
Laravel Socialite is a package developed to abstract away any social authentication complexities and boilerplate code into a fluent and expressive interface. Socialite only supports Google, Facebook, Twitter, Linked In, Github, and Bitbucket as OAuth providers.
Laravel lets you easily and quickly build RESTful APIs. This could be the back-end to a front-end web app, a data source for a mobile app, or a service for other apps or APIs. There are a lot of moving pieces to coding a RESTful API, but Laravel makes it a lot easier.
Laravel Sanctum does not support OAuth2; however, it provides a much simpler API authentication development experience.
Just found my answer. Need to use stateless
in both calls:
Socialite::with('facebook')->stateless()->redirect()->getTargetUrl()
$fb_user = Socialite::with('facebook')->stateless()->user();
Hope this helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With