2023-03-02 15:07:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Extensions;
|
|
|
|
|
|
|
|
use App\Models\WebAuthnAuthenticatable;
|
2023-03-10 22:59:46 +01:00
|
|
|
use Illuminate\Auth\EloquentUserProvider;
|
2023-03-02 15:07:46 +01:00
|
|
|
use Laragear\WebAuthn\Auth\WebAuthnUserProvider;
|
|
|
|
|
|
|
|
class WebauthnTwoFAuthUserProvider extends WebAuthnUserProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Validate a user against the given credentials.
|
|
|
|
*
|
2023-03-17 17:17:04 +01:00
|
|
|
* @param \App\Models\User $user
|
2023-03-02 15:07:46 +01:00
|
|
|
*/
|
2023-03-10 22:59:46 +01:00
|
|
|
public function validateCredentials($user, array $credentials) : bool
|
2023-03-02 15:07:46 +01:00
|
|
|
{
|
|
|
|
if ($user instanceof WebAuthnAuthenticatable && $this->isSignedChallenge($credentials)) {
|
2024-03-29 09:21:00 +01:00
|
|
|
return $this->validateWebAuthn($user);
|
2023-03-02 15:07:46 +01:00
|
|
|
}
|
|
|
|
|
2023-03-18 17:33:43 +01:00
|
|
|
// If the user disabled the fallback, we will validate the credential password.
|
2023-03-02 15:07:46 +01:00
|
|
|
return $user->preferences['useWebauthnOnly'] == false && EloquentUserProvider::validateCredentials($user, $credentials);
|
|
|
|
}
|
|
|
|
}
|