2

最近我正在研究 laravel 5.1 框架并尝试通过社交身份验证(如 facebook 登录)进行用户登录。我从 youtube Laravel 5.1 Socialite Authentication中遵循了本教程

但得到这个异常
InvalidStateException in AbstractProvider.php line 191:

in AbstractProvider.php line 191

在 SocialAuthController.php 中的 AbstractProvider->user() 第 61 行在 SocialAuthController->github_Callback() 在 call_user_func_array(array(object(SocialAuthController), 'github_Callback'), array()) 在 Controller.php 第 256 行在 Controller->callAction ('github_Callback', array()) 在 ControllerDispatcher.php 第 164 行

这是我的代码

// facebook Sociolite for routing 
Route::get('/auth/facebook', 'Auth\SocialAuthController@redirectToProvider');
Route::get('callback_facebook', 'Auth\SocialAuthController@handleProviderCallback');

// 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',
    ],
4

1 回答 1

0

您可以从 laravel官方网站获取详细文档。社交名流教程 在这里

于 2015-09-08T12:05:22.540 回答