Laravel with Socialize(fb)说:AbstractProvider.php第150行中的InvalidStateException:

时间:2016-03-20 15:44:53

标签: php facebook laravel laravel-5.1 laravel-socialite

我尝试在Laravel 5.1项目中实现https://github.com/laravel/socialite

因此,当我阅读文档时,我写道: 在services.php

'facebook' => [
    'client_id' =>  env('FACEBOOK_APP_ID'),
    'client_secret' => env('FACEBOOK_APP_SECRET'),
    'redirect' => env('FACEBOOK_REDIRECT'),
],

也在app.php我添加:

    Laravel\Socialite\SocialiteServiceProvider::class,

和别名:

'Socialite' => Laravel\Socialite\Facades\Socialite::class,

现在在AuthController我添加:

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()
    ];

    Auth::login(User::firstOrCreate($data));

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

和route.php:

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

但是当我试着去http://www.domain.com/social/login/facebook时,我得到了: enter image description here

有什么问题?我犯错误了吗?如何解决这个问题?

更新 我的.env文件是:

FACEBOOK_APP_ID=<app_id>
FACEBOOK_APP_SECRET=<app_secret>
FACEBOOK_REDIRECT=http://www.domain.com/social/login/redirect/facebook

0 个答案:

没有答案