2FAuth/app/Extensions/WebauthnTwoFAuthUserProvider.php

28 lines
874 B
PHP
Raw Normal View History

<?php
namespace App\Extensions;
use App\Models\WebAuthnAuthenticatable;
2023-03-10 22:59:46 +01:00
use Illuminate\Auth\EloquentUserProvider;
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
* @param array $credentials
* @return bool
*/
2023-03-10 22:59:46 +01:00
public function validateCredentials($user, array $credentials) : bool
{
if ($user instanceof WebAuthnAuthenticatable && $this->isSignedChallenge($credentials)) {
return $this->validateWebAuthn();
}
// If the user disabled the fallback is enabled, we will validate the credential password.
return $user->preferences['useWebauthnOnly'] == false && EloquentUserProvider::validateCredentials($user, $credentials);
}
}