From cfc2bb2aeb2f78a5b067bef27dfe48935f1cfdfb Mon Sep 17 00:00:00 2001 From: thiritin Date: Mon, 9 Sep 2024 21:29:20 +0200 Subject: [PATCH] prevent cleaning login sessions upon 2nd login --- app/Http/Controllers/Auth/LoginController.php | 5 ++--- app/Services/Hydra/Client.php | 15 ++++++++------- resources/js/Pages/Auth/Login.vue | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index b67fd44..4e5426e 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -40,8 +40,7 @@ public function view(Request $request) } if ($subject !== null) { - return Redirect::to($hydra->acceptLogin($subject, $loginRequest["challenge"], 3600, - $loginRequest)); + return Redirect::to($hydra->acceptLogin($subject, $loginRequest["challenge"], null, $loginRequest)); } return Inertia::render('Auth/Login'); @@ -56,7 +55,7 @@ public function submit(LoginRequest $request) if (Auth::once($loginData) === true) { $user = Auth::user(); - + $hydra = new Client(); $loginRequest = $hydra->getLoginRequest($request->get('login_challenge')); diff --git a/app/Services/Hydra/Client.php b/app/Services/Hydra/Client.php index 4a3ab87..d439415 100644 --- a/app/Services/Hydra/Client.php +++ b/app/Services/Hydra/Client.php @@ -45,7 +45,7 @@ public function getScopes() public function acceptLogin( string $subject, string $login_challenge, - int $remember_seconds = 0, + int|null $remember_seconds = 0, array|null $loginRequest = null ): string { $hydra = new Client(); @@ -74,14 +74,15 @@ public function acceptLogin( return $hydraResponse['redirect_to']; } - public function acceptLoginRequest(string $userId, string $loginChallenge, int $remember = 0) + public function acceptLoginRequest(string $userId, string $loginChallenge, int|null $remember = 0) { try { - return Http::hydraAdmin()->put('/admin/oauth2/auth/requests/login/accept?challenge='.$loginChallenge, [ - 'subject' => $userId, - 'remember' => ($remember !== 0), - 'remember_for' => $remember, - ])->json(); + $loginRequestBody = ['subject' => $userId]; + if ($remember !== null) { + $loginRequestBody['remember'] = ($remember !== 0); + $loginRequestBody['remember_for'] = $remember; + } + return Http::hydraAdmin()->put('/admin/oauth2/auth/requests/login/accept?challenge='.$loginChallenge, $loginRequestBody)->json(); } catch (Exception $e) { if ($e->getCode() === 404) { diff --git a/resources/js/Pages/Auth/Login.vue b/resources/js/Pages/Auth/Login.vue index 5b3469c..23a8c06 100644 --- a/resources/js/Pages/Auth/Login.vue +++ b/resources/js/Pages/Auth/Login.vue @@ -51,7 +51,7 @@
- +