Laravel Socialite 不适用于 Google Chrome
Laravel Socialite doesn't work on Google Chrome
我在 Laravel Socialite 登录时遇到一个问题,在我的 Chrome 中正常工作,但在其他人中浏览器不工作(在其他浏览器中工作)。在服务器从 7.1 php 更新到 7.3.18 和从 5.8 更新到 Laravel 6 之前,一切正常。我尝试清除所有缓存,将 session 模式更改为 cookie(之前的文件),清除浏览器中的 session 和 cookie,但没有解决问题。
When try to login, give me this
这是我的代码:
public function loginSocial(Request $request){
$this->validate($request, [
'social_type' => 'required|in:google,facebook'
]);
$socialType = $request->get('social_type');
return Socialite::driver($socialType)->stateless()->redirect();
}
public function loginCallback(Request $request){
$socialType = $request->session()->get('social_type');
//Aparently, this get give to $socialType null in ppl browser. I dont understand why this get doesn't works.
$userSocial = Socialite::driver($socialType)->stateless()->user();
//If use 'google' instead $socialType, works fine.
$user = User::where('email',$userSocial->email)->first();
\Auth::login($user);
return redirect()->intended($this->redirectPath());
}
我明白你想做什么,但有时少即是多,多即是少......回调是由提供商而不是用户进行的。无论如何每个社交登录都有不同的方法
// Google login
public function googleSocialLogin(Request $request){
Socialite::driver('google')->stateless()->redirect();
}
// Google callback
public function googleSocialLoginCallback(){
$userSocial = Socialite::driver('google')->stateless()->user();
$user = User::where('email',$userSocial->email)->first();
\Auth::login($user);
return redirect()->intended($this->redirectPath());
}
// Facebook login
public function facebookSocialLogin(Request $request){
Socialite::driver('facebook')->stateless()->redirect();
}
// Facebook callback
public function facebookSocialLoginCallback(){
$userSocial = Socialite::driver('facebook')->stateless()->user();
$user = User::where('email',$userSocial->email)->first();
\Auth::login($user);
return redirect()->intended($this->redirectPath());
}
随着方法的分离,不同的社交登录会有不同的路由,IMO 更好,因为它们的 return 参数略有不同,您可能希望在未来为特定的社交登录执行额外的功能.
我在 Laravel Socialite 登录时遇到一个问题,在我的 Chrome 中正常工作,但在其他人中浏览器不工作(在其他浏览器中工作)。在服务器从 7.1 php 更新到 7.3.18 和从 5.8 更新到 Laravel 6 之前,一切正常。我尝试清除所有缓存,将 session 模式更改为 cookie(之前的文件),清除浏览器中的 session 和 cookie,但没有解决问题。
When try to login, give me this
这是我的代码:
public function loginSocial(Request $request){
$this->validate($request, [
'social_type' => 'required|in:google,facebook'
]);
$socialType = $request->get('social_type');
return Socialite::driver($socialType)->stateless()->redirect();
}
public function loginCallback(Request $request){
$socialType = $request->session()->get('social_type');
//Aparently, this get give to $socialType null in ppl browser. I dont understand why this get doesn't works.
$userSocial = Socialite::driver($socialType)->stateless()->user();
//If use 'google' instead $socialType, works fine.
$user = User::where('email',$userSocial->email)->first();
\Auth::login($user);
return redirect()->intended($this->redirectPath());
}
我明白你想做什么,但有时少即是多,多即是少......回调是由提供商而不是用户进行的。无论如何每个社交登录都有不同的方法
// Google login
public function googleSocialLogin(Request $request){
Socialite::driver('google')->stateless()->redirect();
}
// Google callback
public function googleSocialLoginCallback(){
$userSocial = Socialite::driver('google')->stateless()->user();
$user = User::where('email',$userSocial->email)->first();
\Auth::login($user);
return redirect()->intended($this->redirectPath());
}
// Facebook login
public function facebookSocialLogin(Request $request){
Socialite::driver('facebook')->stateless()->redirect();
}
// Facebook callback
public function facebookSocialLoginCallback(){
$userSocial = Socialite::driver('facebook')->stateless()->user();
$user = User::where('email',$userSocial->email)->first();
\Auth::login($user);
return redirect()->intended($this->redirectPath());
}
随着方法的分离,不同的社交登录会有不同的路由,IMO 更好,因为它们的 return 参数略有不同,您可能希望在未来为特定的社交登录执行额外的功能.