Level 39
May 16, 2022
1
Level 1
Laravel 8 | Socialite: Session Not Generated When Using 'database' driver
Context:
- Laravel 8 | PHP 8.0 | laravel/socialite "^5.5" | socialiteproviders/manager "^4.1"
- Running on Laravel Forge
- I'm using Laravel Socialite with a custom Socialite Provider to authorize users via oauth 2.0 and authenticate them in Laravel.
- When using the
filesession driver, a session is generated in the filesystem, and state is persisted. - Example session when using
filedriver: (I did no configuration. This worked out of the box.)
a:3:{s:6:"_token";s:40:"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";s:6:"_flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}s:50:"login_web_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";i:1;}
Issue:
- When I change the Laravel Session driver to
database, a session does not appear to be generated in the sessions table in the databse, so therefore I assume the session state is not persisted. - An exception is thrown after the oauth server redirects to my
oauth/callback route:
Laravel\Socialite\Two\InvalidStateException
if ($this->hasInvalidState()) {
throw new InvalidStateException();
}
What I've tried
- I've tried running the default
php artisan session:tablewhich creates this snippet in migrations, and I added astatecolumn.
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->string('state')->nullable();
$table->text('user_agent')->nullable();
$table->text('payload');
$table->integer('last_activity')->index();
});
Any help is appreciated!
Please or to participate in this conversation.