Reputation: 543
Getting the following error when using Socialite to authenticate with Facebook. Using Laravel 5.2 and this is the first time I am trying to implement Socialite. Any ideas ?
FatalErrorException in AbstractProvider.php line 134:
Call to a member function set() on a non-object
Route :-
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 setup as follows with details in the .env file :-
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => env('FACEBOOK_REDIRECT'),
],
The same error was reported here but no response :- https://laracasts.com/discuss/channels/laravel/laravel-socialite-session-errors-in-52/replies/125233
Upvotes: 1
Views: 1963
Reputation: 1
try this code in your 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');
});
Upvotes: 0
Reputation: 5005
The reason you are receiving this error is because there is no session started. You have to assign the \Illuminate\Session\Middleware\StartSession
middleware to the route your calling.
In previous version of Laravel this was already assigned within the $middleware
property, found in the file app/Http/Kernel.php
.
Upvotes: 0
Reputation: 81
Had the same problem...
Found an answer here: in routes.php, did you define your routes inside the web middleware group? This seems to be a common problem with 5.2 upgrades :)
It looks like you have to put your routes in a MiddleWare because it includes Session creation which is needed in the AbstractProvider.php 134
$this->request->getSession()->set('state', $state = Str::random(40));
This is how my code routes.php looks like now (and works):
<?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');
});
Upvotes: 8