From 54c72078365150572e72e73e9beaf6b7877173a1 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 13 Feb 2022 14:23:20 -0500 Subject: [PATCH] Fix authentication request creation --- app/Http/Controllers/Auth/LoginController.php | 22 +++++++++---------- ...ratePublicKeyCredentialsRequestService.php | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 8b47f16d7..2b5979dfe 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -75,7 +75,7 @@ class LoginController extends AbstractLoginController return; } - if (!$user->use_totp && empty($user->security_keys_count)) { + if (!$user->use_totp && empty($user->securityKeys)) { return $this->sendLoginResponse($user, $request); } @@ -88,21 +88,19 @@ class LoginController extends AbstractLoginController $response = [ 'complete' => false, - 'methods' => array_filter([ + 'methods' => array_values(array_filter([ $user->use_totp ? self::METHOD_TOTP : null, - $user->security_keys_count > 0 ? self::METHOD_WEBAUTHN : null, - ]), + !empty($user->securityKeys) ? self::METHOD_WEBAUTHN : null, + ])), 'confirmation_token' => $token, ]; - if ($user->security_keys_count > 0) { -// $key = $this->service->handle($user); -// -// $request->session()->put(self::SESSION_PUBLICKEY_REQUEST, $publicKey); -// -// $response['webauthn'] = [ -// 'public_key' => $publicKey, -// ]; + if (!empty($user->securityKeys)) { + $key = $this->service->handle($user); + + $request->session()->put(self::SESSION_PUBLICKEY_REQUEST, $key); + + $response['webauthn'] = ['public_key' => $key]; } return new JsonResponse($response); diff --git a/app/Services/Users/SecurityKeys/GeneratePublicKeyCredentialsRequestService.php b/app/Services/Users/SecurityKeys/GeneratePublicKeyCredentialsRequestService.php index 4a8be3c6d..234e00162 100644 --- a/app/Services/Users/SecurityKeys/GeneratePublicKeyCredentialsRequestService.php +++ b/app/Services/Users/SecurityKeys/GeneratePublicKeyCredentialsRequestService.php @@ -27,7 +27,7 @@ class GeneratePublicKeyCredentialsRequestService { $credentials = $user->securityKeys->map(function (SecurityKey $key) { return $key->getPublicKeyCredentialDescriptor(); - }); + })->values()->toArray(); $response = $this->serverRepository->getServer($user) ->generatePublicKeyCredentialRequestOptions(