使用带有API的Laravel Socialite吗? [英] Using Laravel Socialite with an API?

查看:72
本文介绍了使用带有API的Laravel Socialite吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过api使用Laravel Socialite软件包.我尝试将代码传递到我的api中以获取用户,但它一直给我一个错误:

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

由于我正在通过API进行请求,因此请执行以下步骤.

Since I'm doing the request over an API, I take the following steps.

向api发送请求以获取网址以获取代码:

Send a request to api for the url to fetch the code:

Socialite::with('facebook')->stateless()->redirect()->getTargetUrl()

然后使用上面获取的网址进行请求,该网址将使用 code 参数进行重定向.

Then make a request with the above fetched url, which redirects with the code parameter.

将代码发送到api并获取用户:

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.

我以前使用过该软件包,当我只有一个可以重新加载页面的应用程序时,它可以很好地工作.但是,当我将其发送到api(在其​​他域中)时,它崩溃了.我认为代码的生成方式存在一些问题.反正有解决此问题的方法吗?

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?

推荐答案

刚刚找到了我的答案.在两个调用中都需要使用 stateless :

Just found my answer. Need to use stateless in both calls:

Socialite::with('facebook')->stateless()->redirect()->getTargetUrl()

$fb_user = Socialite::with('facebook')->stateless()->user();

希望这对某人有帮助.

这篇关于使用带有API的Laravel Socialite吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆