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 // Cookie name
'name' => env('SESSION_NAME', 'session'), '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 // 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' => [ 'options' => [
'cookie_httponly' => true, 'cookie_httponly' => true,
'name' => $sessionConfig['name'], 'name' => $sessionConfig['name'],
'cookie_lifetime' => (int)($sessionConfig['lifetime'] * 24 * 60 * 60),
], ],
'handler' => $handler, 'handler' => $handler,
]); ]);

View File

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