【问题标题】:Laravel 5.2 / Socialite FatalErrorException in AbstractProvider.php line 134:AbstractProvider.php 第 134 行中的 Laravel 5.2 / Socialite FatalErrorException:
【发布时间】:2016-01-06 05:30:50
【问题描述】:

使用社交名流向 Facebook 进行身份验证时出现以下错误。使用 Laravel 5.2,这是我第一次尝试实现 Socialite。有什么想法吗?

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

路线:-

Route::get('/login', 'AuthController@login');

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

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

'facebook' => [
    'client_id'     => env('FACEBOOK_CLIENT_ID'),
    'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
    'redirect'      => env('FACEBOOK_REDIRECT'),
],

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

【问题讨论】:

    标签: php laravel laravel-5 oauth-2.0


    【解决方案1】:

    遇到同样的问题...

    在这里找到答案:in routes.php, did you define your routes inside the web middleware group? This seems to be a common problem with 5.2 upgrades :)

    看起来你必须把你的路由放在一个 MiddleWare 中,因为它包括 AbstractProvider.php 134 中需要的会话创建

    $this->request->getSession()->set('state', $state = Str::random(40));
    

    这就是我的代码 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');
    
    });
    

    【讨论】:

    • 刚刚看到您已经有了相同的链接,现在可以找到答案了......不过还是把它放在这里很好。我现在正在努力处理回调,因为没有用户并且它会引发无效状态。
    • 将路由放入 web 中间件修复了它。谢谢!
    【解决方案2】:

    您收到此错误的原因是没有启动会话。您必须将 \Illuminate\Session\Middleware\StartSession 中间件分配给您的呼叫路由。

    在以前的 Laravel 版本中,这已经在 $middleware 属性中分配,在文件 app/Http/Kernel.php 中找到。

    【讨论】:

      【解决方案3】:

      在你的 route.php 中试试这个代码

      <?php
      
      /*
      |--------------------------------------------------------------------------
      | Application Routes
      |--------------------------------------------------------------------------
      |
      | Here is where you can register all of the routes for 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::group(['middleware' => ['web']], function () {
      
          Route::get('/', function () {
              return view('welcome');
          });
      
      });
      
      Route::group(['middleware' => 'web'], function () {
          Route::auth();
      
          Route::get('/home', 'HomeController@index');
      
          Route::get('/redirect', 'SocialAuthController@redirect');
      
          Route::get('/callback', 'SocialAuthController@callback');
      
      });
      

      【讨论】:

        猜你喜欢
        • 2017-04-28
        • 2016-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-29
        • 1970-01-01
        • 2018-01-05
        相关资源
        最近更新 更多