Enhance WebAuthn handling and error management
- Improve user verification in `authentication.php` by adding a check for user existence and throwing meaningful exceptions for missing users. - Refactor `webauthn.php` to handle Base64URL decoding and COSE key normalization for consistent WebAuthn library compatibility. - Extend error logging with additional context for debugging (e.g., public key hex representation). - Add utility functions for Base64URL decoding and checking PEM/DER format. - Update `passkeysRoute.php` to normalize public keys and handle errors gracefully during WebAuthn workflows.
This commit is contained in:
@@ -74,8 +74,12 @@ class authentication implements authentication_i
|
||||
{
|
||||
// Create a token
|
||||
$token = bin2hex(random_bytes(32));
|
||||
// Get the user id
|
||||
$user_id = (new users_o())->getUserByCustomerNumber($customer_number)->id;
|
||||
// Resolve the user by customer number and ensure it exists to avoid accessing an uninitialized typed property
|
||||
$user = (new users_o())->getUserByCustomerNumber($customer_number);
|
||||
if (!$user->exists()) {
|
||||
throw new \Exception('User not found for customer number: ' . $customer_number);
|
||||
}
|
||||
$user_id = $user->id;
|
||||
// Save the token in the database
|
||||
(new tokens_o())->create($user_id, $token, 'AUTH_TOKEN');
|
||||
return $token;
|
||||
|
||||
Reference in New Issue
Block a user