AbstractProvider.php第134行中的Laravel 5.2/Socialite FatalErrorException:

Rob*_*ert 1 php oauth-2.0 laravel laravel-5

使用Socialite通过Facebook进行身份验证时出现以下错误.使用Laravel 5.2,这是我第一次尝试实现Socialite.有任何想法吗 ?

FatalErrorException in AbstractProvider.php line 134:
Call to a member function set() on a non-object
Run Code Online (Sandbox Code Playgroud)

路线: -

Route::get('/login', 'AuthController@login');
Run Code Online (Sandbox Code Playgroud)

AuthController.php: -

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class AuthController extends Controller
{
public function login()
{
  return \Socialite::with('facebook')->redirect();
}
}
Run Code Online (Sandbox Code Playgroud)

services.php设置如下.env文件中的详细信息: -

'facebook' => [
    'client_id'     => env('FACEBOOK_CLIENT_ID'),
    'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
    'redirect'      => env('FACEBOOK_REDIRECT'),
],
Run Code Online (Sandbox Code Playgroud)

这里报告了同样的错误但没有回复: - https://laracasts.com/discuss/channels/laravel/laravel-socialite-session-errors-in-52/replies/125233

小智 8

有同样的问题......

在这里找到答案:在routes.php中,您是否在Web中间件组中定义了路由?这似乎是5.2升级的常见问题:)

您似乎必须将路由放在MiddleWare中,因为它包含AbstractProvider.php中需要的会话创建134

$this->request->getSession()->set('state', $state = Str::random(40));
Run Code Online (Sandbox Code Playgroud)

这就是我的代码routes.php现在的样子(并且有效):

    <?php

/*
|--------------------------------------------------------------------------
| Routes File
|--------------------------------------------------------------------------
|
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('admin', function () {
    return view('admin_template');
});

Route::get('test', 'TestController@index');


/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/

Route::group(['middleware' => ['web']], function () {
    //
    Route::get('auth/google', 'Auth\AuthController@redirectToProvider');
    Route::get('auth/google/callback', 'Auth\AuthController@handleProviderCallback');

});
Run Code Online (Sandbox Code Playgroud)