最近我的工作laravel 5.1框架,並試圖通過社會認證,使用戶登錄像Facebook登錄.. 我也跟着從YouTube Laravel 5.1 Socialite AuthenticationLaravel 5.1社會認證工作不正常
本教程,但得到這個異常
InvalidStateException in AbstractProvider.php line 191:
in AbstractProvider.php line 191
在AbstractProvider->用戶()在SocialAuthController.php線61 在SocialAuthController-> github_Callback() 在call_us er_func_array(陣列(對象(SocialAuthController), 'github_Callback'),陣列())在ControllerDispatcher.php線Controller.php這樣線256 在控制器 - > callAction( 'github_Callback',陣列())164
這裏是我的代碼
// facebook Sociolite for routing
Route::get('/auth/facebook', 'Auth\[email protected]');
Route::get('callback_facebook', 'Auth\[email protected]');
// AuthController
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Socialite;
use Auth;
use redirect;
class AuthController extends Controller
{
class SocialAuthController extends Controller{
// For Facebook
public function redirectToProvider(){
return Socialite::driver('facebook')->redirect();
}
public function handleProviderCallback(){
$curl = curl_init();
curl_setopt($curl , CURLOPT_SSL_VERIFYPEER, false);
$user = Socialite::driver('facebook')->user();
$data = ['name'=>$user->name, 'email'=>$user->email, 'password'=>$user->token];
$userDB = User::where('email',$user->email)->first();
if (!is_null($userDB)){
Auth::login($userDB);
}
else{
Auth::login($this->create($data));
}
return redirect('/pages/profile');
}
}
}
config\service.php
'facebook' => [
'client_id' => '513845902100524',
'client_secret' => '135699237e16cd3a50d2cbfec3a5e58c',
'redirect' => 'http://localhost:8000/callback_facebook',
],
我身邊有一個cookie問題。我解決了它使用這個答案http://stackoverflow.com/a/31738836/1090395 –