@@ -44,6 +44,13 @@ public function getConfigSchema(): Nette\Schema\Schema
4444 ),
4545 'roles ' => Expect::arrayOf ('string|array|null ' )->deprecated (), // role => parent(s)
4646 'resources ' => Expect::arrayOf ('string|null ' )->deprecated (), // resource => parent
47+ 'authentication ' => Expect::structure ([
48+ 'storage ' => Expect::anyOf ('session ' , 'cookie ' )->default ('session ' ),
49+ 'expiration ' => Expect::string ()->dynamic (),
50+ 'cookieName ' => Expect::string (),
51+ 'cookieDomain ' => Expect::string (),
52+ 'cookieSamesite ' => Expect::anyOf ('Lax ' , 'Strict ' , 'None ' ),
53+ ]),
4754 ]);
4855 }
4956
@@ -57,9 +64,20 @@ public function loadConfiguration()
5764 $ builder ->addDefinition ($ this ->prefix ('passwords ' ))
5865 ->setFactory (Nette \Security \Passwords::class);
5966
67+ $ auth = $ config ->authentication ;
6068 $ storage = $ builder ->addDefinition ($ this ->prefix ('userStorage ' ))
6169 ->setType (Nette \Security \UserStorage::class)
62- ->setFactory (Nette \Bridges \SecurityHttp \SessionStorage::class);
70+ ->setFactory ([
71+ 'session ' => Nette \Bridges \SecurityHttp \SessionStorage::class,
72+ 'cookie ' => Nette \Bridges \SecurityHttp \CookieStorage::class,
73+ ][$ auth ->storage ]);
74+
75+ if ($ auth ->storage === 'cookie ' ) {
76+ if ($ auth ->cookieDomain === 'domain ' ) {
77+ $ auth ->cookieDomain = $ builder ::literal ('$this->getByType(Nette\Http\IRequest::class)->getUrl()->getDomain(2) ' );
78+ }
79+ $ storage ->addSetup ('setCookieParameters ' , [$ auth ->cookieName , $ auth ->cookieDomain , $ auth ->cookieSamesite ]);
80+ }
6381
6482 $ builder ->addDefinition ($ this ->prefix ('legacyUserStorage ' )) // deprecated
6583 ->setType (Nette \Security \IUserStorage::class)
@@ -68,6 +86,10 @@ public function loadConfiguration()
6886 $ user = $ builder ->addDefinition ($ this ->prefix ('user ' ))
6987 ->setFactory (Nette \Security \User::class);
7088
89+ if ($ auth ->expiration ) {
90+ $ user ->addSetup ('setExpiration ' , [$ auth ->expiration ]);
91+ }
92+
7193 if ($ config ->users ) {
7294 $ usersList = $ usersRoles = $ usersData = [];
7395 foreach ($ config ->users as $ username => $ data ) {
0 commit comments