55use Illuminate \Contracts \Auth \Authenticatable as User ;
66use Illuminate \Contracts \Cache \Repository as Cache ;
77use Illuminate \Http \Request ;
8+ use LaravelWebauthn \Events \WebauthnAuthenticate ;
89use LaravelWebauthn \Exceptions \ResponseMismatchException ;
910use LaravelWebauthn \Services \Webauthn ;
1011use ParagonIE \ConstantTime \Base64UrlSafe ;
@@ -36,15 +37,19 @@ public function __invoke(?User $user, array $data): bool
3637 $ content = json_encode ($ data , flags: JSON_THROW_ON_ERROR );
3738 $ publicKeyCredential = $ this ->loader ->deserialize ($ content , PublicKeyCredential::class, 'json ' );
3839
40+ $ webauthnKey = $ this ->getKey ($ user , $ publicKeyCredential );
41+
3942 // Check the response against the request
4043 $ this ->validator ->check (
41- $ this -> getCredentialSource ( $ user , $ publicKeyCredential ) ,
44+ $ webauthnKey -> publicKeyCredentialSource ,
4245 $ this ->getResponse ($ publicKeyCredential ),
4346 $ this ->pullPublicKey ($ user ),
4447 $ this ->request ->host (),
4548 optional ($ user )->getAuthIdentifier ()
4649 );
4750
51+ WebauthnAuthenticate::dispatch ($ webauthnKey );
52+
4853 return true ;
4954 }
5055
@@ -87,7 +92,7 @@ protected function getResponse(PublicKeyCredential $publicKeyCredential): Authen
8792 /**
8893 * Get credential source from user and public key.
8994 */
90- protected function getCredentialSource (?User $ user , PublicKeyCredential $ publicKeyCredential )
95+ protected function getKey (?User $ user , PublicKeyCredential $ publicKeyCredential )
9196 {
9297 $ credentialId = $ publicKeyCredential ->rawId ;
9398
@@ -97,7 +102,6 @@ protected function getCredentialSource(?User $user, PublicKeyCredential $publicK
97102 )->where (
98103 fn ($ query ) => $ user !== null ? $ query ->where ('user_id ' , $ user ->getAuthIdentifier ()) : $ query
99104 )
100- ->firstOrFail ()
101- ->publicKeyCredentialSource ;
105+ ->firstOrFail ();
102106 }
103107}
0 commit comments