1
votes

I'm trying to do a Custom Authentication with third-party authentication API which means I have a login endpoint in another project (Lumen Project). and I've found a tutorial about how to do it but using Laravel 5.2 on here.

I'm using:

  • Laravel 7
  • PhpRedis/Redis

The ERROR:

RuntimeException: Session store not set on request.

The tutorial is kinda simple. The steps follow as:

  1. Install PhpRedis and Guzzle.
  2. Create custom auth controllers which include Throttles.php where works the Cache.
  3. Override Laravel’s authentication middleware (Authenticate.php).

I've done all the steps and I didn't miss anything. What I've tried to fix this but none of them works:

  1. I used the web middleware in the login routes but It won't work and I don't know why

    Route::group(['middleware' => ['web']], function () {
        Route::get('login', 'Auth\CustomAuthController@showLoginForm');
        Route::post('login', 'Auth\CustomAuthController@login');
        Route::get('logout', 'Auth\CustomAuthController@logout');
    });
    

And you can see here my Kernel.php by default.

protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
  1. Configure the Cache driver

My .env file

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
QUEUE_CONNECTION=sync
SESSION_DRIVER=redis
SESSION_LIFETIME=120

My database.php

'redis' => [

        'client' => env('REDIS_CLIENT', 'predis'),

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'redis'),
            'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
        ],

        'default' => [
            'host' => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
            'read_write_timeout' => 60,
        ],

        'cache' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_CACHE_DB', '1'),
        ],

        'session' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 1,
        ],

    ],

And my session.php

'connection' => 'session',

I've tried all that and none of these worked. I don't know what's happening, maybe Laravel 7 needs something else or I'm missing something. Just someone could know why the web middleware isn't working?

1

1 Answers

0
votes

Flor,

I was facing the exact same problem. Got it working by making the following change in AuthenticationRequest.php

class AuthenticationRequest extends Request

to

class AuthenticationRequest extends FormRequest

You would need the following import as well

use Illuminate\Foundation\Http\FormRequest;