我有一个单页应用程序与vue.js
使用Laravel 5.5
作为其api。我想添加谷歌登录,但我很困惑,从哪里开始。我之前使用laravel socialite
添加谷歌登录,但这是纯粹的laravel应用程序而不是laravel api。
任何人都可以指出我能阅读的一些资源。是否有类似社交名媛的包,在这种情况下是否有办法使用社交名媛。
看看hellojs
Hellojs让它变得简单。允许您打开弹出窗口以便与社交提供程序一起登录并返回访问令牌。然后在后端使用访问令牌来获取用户。
所以你的js看起来像这样
hello
.login(network)
.then(
() => {
const authRes = hello(network).getAuthResponse();
axios
.get('api/link/to/sociak/callback',{
params:{
access_token : authRes.access_token,
provider: network
}
})
.then((response) => {console.log(response.data.token)})})
.catch((error) => {console.log(error.response.data)})
},
(e) => {
console.log(e)
}
)
并在您的控制器中处理它像..
public function handleProviderCallback(Request $request)
{
$s_user = Socialite::with($request->provider)->stateless()->userFromToken($request->access_token);
//your logic here...
}
希望它能让你更清楚。我只是在努力解决这个问题,你好js让我的生活变得简单
与上一个答案相反,我使用qazxsw poi添加google身份验证窗口并获取令牌(带有'email,profile'范围)。
然后将其发送到laravel后端(安装了vue-hellojs和CORS),该后端检查是否有用户使用该电子邮件并使用laravel google socialite provider作为登录来响应vue SPA。