如何将在社交名流回调中获得的访问令牌返回给客户端?我需要将此数据返回给 vue 以便用户登录。 令牌数据
这是我在 vue 中获取重定向 url 的代码
googleLogin(){
const self = this;
let socialLogin = {
name: 'google'
};
self.$http.post(`api/googleLogin`, socialLogin)
.then(response => {
console.log('GOOGLE LOGIN RESPONSE ', response.body);
window.location = response.body;
})
}
Run Code Online (Sandbox Code Playgroud)
对于后端
public function googleLogin(Request $request){
$socialType = $request->name;
return response()->json(
Socialite::driver($socialType)
->with(['social_type' => $socialType])
->stateless()
->redirect()
->getTargetUrl()
);
}
public function googleLoginCallback(){
$http = new \GuzzleHttp\Client;
$user = Socialite::with('google')->stateless()->user();
$userCredentials = [
'token' => $user->token,
'refreshToken' => $user->refreshToken,
'expiresIn' => $user->expiresIn,
];
$response = …Run Code Online (Sandbox Code Playgroud) single-page-application vue.js laravel-socialite laravel-5.6