2016-08-30 55 views
0

我在Laravel 5.1上安裝Socialite插件真的很麻煩。與Laravel 5.1集成社交站InvalidState問題

首先,我有這樣的AuthCOntroller.php代碼:

public function redirectToProvider($provider) 
    { 
     return Socialite::driver($provider)->redirect(); 
    } 

    public function handleProviderCallback($provider) 
{ 
//notice we are not doing any validation, you should do it 

    $user = Socialite::driver($provider)->user(); 

    // stroing data to our use table and logging them in 
    $data = [ 
     'name' => $user->getName(), 
     'email' => $user->getEmail() 
    ]; 

    // Here, check if the user already exists in your records 

    $my_user = User::where('email','=', $user->getEmail())->first(); 
    if($my_user === null) { 
      Auth::login(User::firstOrCreate($data)); 
    } else { 
     Auth::login($my_user); 
    } 

    //after login redirecting to home page 
    return redirect($this->redirectPath()); 
} 

和route.php:

Route::get('/social/login/redirect/{provider}', ['uses' => 'Auth\[email protected]', 'as' => 'social.login']); 
Route::get('/social/login/{provider}', 'Auth\[email protected]'); 

現在,當我嘗試我的域名:http://mydomain.me/social/login/redirect/facebook

回我:

http://mydomain.me/social/login/facebook?code=AQAl29aq2-rX9L5-9GmiIwqstR-ETC ETC ETC#_=_ 

和錯誤: enter image description here

這裏有什麼問題?

我嘗試: 域從空在session.php文件更改爲「mydomain.me」,同時也嘗試:

php artisan cache:clear 
php artisan config:clear 
php artisan route:clear 
php artisan clear-compiled 

不要再工作......請幫我解決這個問題!

回答

1
  1. 什麼是您的會話驅動程序設置爲?如果它是數組,那麼這將不起作用。你能否確認會話在你的應用程序中完全正常工作?
  2. 它看起來像你沒有得到state查詢字符串回/social/login/facebook你能確認你可以看到重定向URL中的查詢字符串(即當你看到Facebook登錄頁面)嗎?
  3. 此外,您應該檢查您的Facebook應用程序設置,並檢查與您的網站匹配的回調URL。
+0

不,我不知道什麼是問題... 10天我試圖解決這個問題! –

+0

你還沒有回答我的任何問題 – fire

+0

1.我的基本登錄工作很好。 2.是的,我看到像.me/social/login/facebook這樣的查詢字符串?code = AQAl29aq2-rX9L5-9GmiIwqstR-ETC ETC ETC#_ = _ 3. fb應用程序正常,一切都按照慣例設置...相同的代碼在其他應用程序的作品很好 –