Laravel Socialite: InvalidStateException

后端 未结 25 1197
感动是毒
感动是毒 2020-11-27 13:56

I\'m using Laravel Socialite to add a Facebook connect button on a website. Sometimes, I\'ve got this error on callback:

exception \'Laravel\\Socialite\\Two\         


        
25条回答
  •  被撕碎了的回忆
    2020-11-27 14:21

    Got the Solution - Update November 2018

    public function redirectToGoogle(Request $request)
    {
        /**
         * @var GoogleProvider $googleDriver
         */
        $googleDriver = Socialite::driver("google");
        return $googleDriver->redirect();
    }
    
    public function fromGoogle(Request $request)
    {
        try {
    /*
    Solution Starts ----
    */
            if (empty($_GET)) {
                $t = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
                parse_str($t, $output);
                foreach ($output as $key => $value) {
                    $request->query->set($key, $value);
                }
            }
    /*
    Solution Ends ----
    */
            /**
             * @var GoogleProvider $googleDriver
             */
            $googleDriver = Socialite::driver("google");
            print_r($googleDriver->user());
        } catch (\Exception $e) {
            print_r($e->getMessage());
        }
    

提交回复
热议问题