make session lifetime configurable

This commit is contained in:
Xu 2022-10-21 18:16:49 +02:00 committed by Igor Scheller
parent c0a39cb2a1
commit 2391415969
3 changed files with 14 additions and 4 deletions

View File

@ -345,6 +345,9 @@ return [
// Cookie name
'name' => env('SESSION_NAME', 'session'),
// Lifetime in days
'lifetime' => env('SESSION_LIFETIME', 30)
],
// IP addresses of reverse proxies that are trusted, can be an array or a comma separated list

View File

@ -62,6 +62,7 @@ class SessionServiceProvider extends ServiceProvider
'options' => [
'cookie_httponly' => true,
'name' => $sessionConfig['name'],
'cookie_lifetime' => (int)($sessionConfig['lifetime'] * 24 * 60 * 60),
],
'handler' => $handler,
]);

View File

@ -53,13 +53,19 @@ class SessionServiceProviderTest extends ServiceProviderTest
[Session::class],
[
NativeSessionStorage::class,
['options' => ['cookie_httponly' => true, 'name' => 'session'], 'handler' => null],
[
'options' => ['cookie_httponly' => true, 'name' => 'session', 'cookie_lifetime' => 172800],
'handler' => null
],
],
[Session::class],
[DatabaseHandler::class],
[
NativeSessionStorage::class,
['options' => ['cookie_httponly' => true, 'name' => 'foobar'], 'handler' => $databaseHandler],
[
'options' => ['cookie_httponly' => true, 'name' => 'foobar', 'cookie_lifetime' => 432000],
'handler' => $databaseHandler
],
],
[Session::class]
)
@ -101,8 +107,8 @@ class SessionServiceProviderTest extends ServiceProviderTest
->method('get')
->with('session')
->willReturnOnConsecutiveCalls(
['driver' => 'native', 'name' => 'session'],
['driver' => 'pdo', 'name' => 'foobar']
['driver' => 'native', 'name' => 'session', 'lifetime' => 2],
['driver' => 'pdo', 'name' => 'foobar', 'lifetime' => 5]
);
$app->expects($this->atLeastOnce())