Skip to content

Commit

Permalink
prevent cleaning login sessions upon 2nd login
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiritin committed Sep 9, 2024
1 parent 063774c commit cfc2bb2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
5 changes: 2 additions & 3 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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'));

Expand Down
15 changes: 8 additions & 7 deletions app/Services/Hydra/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</div>
<div class="relative flex items-start">
<div class="flex items-center h-5">
<Checkbox id="remember" :binary="true" v-model="form.remember" name="remember"/>
<Checkbox input-id="remember" :binary="true" v-model="form.remember" name="remember"/>
</div>
<div class="ml-3 text-sm">
<label
Expand Down

0 comments on commit cfc2bb2

Please sign in to comment.