RuntimeException-未根据请求设置会话存储-Laravel Socialite-Facebook

时间:2018-10-21 16:45:24

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

我正在使用Laravel 5.7Laravel/Socialite 3.1

我想使用刚刚为此项目配置的Facebook应用程序登录。

这些是我为此配置的主要文件:

/。env

...
FACEBOOK_CLIENT_ID=***
FACEBOOK_CLIENT_SECRET=***
FACEBOOK_CALLBACK_URL=http://localhost:8000/auth/facebook/callback

/config/services.php

<?php

return [
    ...
    'facebook' => [
        'client_id' => env('FACEBOOK_CLIENT_ID'),
        'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
        'redirect' => env('FACEBOOK_CALLBACK_URL'),

    ],
];

/routes/api.php

<?php

use Illuminate\Http\Request;

...

Route::get('auth/facebook', 'SocialiteController@redirectToProviderFacebook');
Route::get('auth/facebook/callback', 'SocialiteController@handleProviderCallbackFacebook');

/app/Http/Controllers/SocialiteController.php

<?php

namespace App\Http\Controllers;

use Socialite;

class SocialiteController extends Controller
{
    public function redirectToProviderFacebook()
    {
        return Socialite::driver('facebook')->redirect();
    }

    public function handleProviderCallbackFacebook()
    {
        $user = Socialite::driver('facebook')->user();
        print_r($user->token);
    }
}

我的问题是由于某种原因我得到了错误:

RuntimeException
Session store not set on request.

如下图所示:

enter image description here

我根本不想在该项目上使用会话。我只想从token内的回调中从Facebook获取function handleProviderCallbackFacebook()

关于如何解决此问题的任何想法?

谢谢!

1 个答案:

答案 0 :(得分:1)

来自社交名流documentation

  

无状态方法可以用于禁用会话状态验证。将社交身份验证添加到API时,这很有用:

return Socialite::driver('google')->stateless()->user();