关于这个问题已经有几个关于SO的帖子,并尝试了我发现的所有解决方案,我确信我的代码特别错误。这是我的Facebook社交登录代码的当前迭代。
要清楚,此代码大约有90%的时间都可以使用。对于我网站上大约10%的用户,他们会触发无效的状态异常错误,无法登录。
我打算下个月在Laravel 5.3上重建整个网站,所以我只需要这个修复程序可以持续30天。
这是我的代码:
public function create()
{
return Socialite::driver('facebook')->redirect();
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$socialUser = Socialite::driver('facebook')->user();
$user = User::firstOrNew(['socialite_provider' => 'facebook', 'socialite_id' => $socialUser->getId()]);
$user->socialite_provider = 'facebook';
$user->socialite_id = $socialUser->getId();
$user->socialite_nickname = $socialUser->getNickname();
$user->socialite_name = $socialUser->getName();
$user->socialite_avatar = $socialUser->getAvatar();
$user->socialite_email = $socialUser->getEmail();
$user->save();
/*
* Hack to fix invalid state error, I think this helped a little but it's still not working for all users.
*/
$state = $request->get('state');
$request->session()->put('state', $state);
if (Auth::check() == false) {
session()->regenerate();
}
// Update orders so that we don't lose our guest cart
$oldSessionId = Session::getId();
Auth::login($user, true);
$newSessionId = Session::getId();
Order::updateSession($oldSessionId, $newSessionId);
return redirect()->intended('/');
}
答案 0 :(得分:0)
此问题已在Laravel 5.3中使用 - > stateless()。
解决https://laravel.com/docs/5.3/authentication#stateless-http-basic-authentication