66use Illuminate \Contracts \Cache \Repository as Cache ;
77use Illuminate \Http \Request ;
88use LaravelWebauthn \Exceptions \ResponseMismatchException ;
9- use Psr \Http \Message \ServerRequestInterface ;
9+ use LaravelWebauthn \Services \Webauthn ;
10+ use ParagonIE \ConstantTime \Base64UrlSafe ;
1011use Webauthn \AuthenticatorAssertionResponse ;
1112use Webauthn \AuthenticatorAssertionResponseValidator ;
1213use Webauthn \PublicKeyCredential ;
@@ -18,7 +19,6 @@ class CredentialAssertionValidator extends CredentialValidator
1819 public function __construct (
1920 Request $ request ,
2021 Cache $ cache ,
21- protected ServerRequestInterface $ serverRequest ,
2222 protected PublicKeyCredentialLoader $ loader ,
2323 protected AuthenticatorAssertionResponseValidator $ validator
2424 ) {
@@ -37,10 +37,10 @@ public function __invoke(User $user, array $data): bool
3737
3838 // Check the response against the request
3939 $ this ->validator ->check (
40- $ publicKeyCredential -> getRawId ( ),
40+ $ this -> getCredentialSource ( $ user , $ publicKeyCredential ),
4141 $ this ->getResponse ($ publicKeyCredential ),
4242 $ this ->pullPublicKey ($ user ),
43- $ this ->serverRequest ,
43+ $ this ->request -> host () ,
4444 $ user ->getAuthIdentifier ()
4545 );
4646
@@ -74,4 +74,19 @@ protected function getResponse(PublicKeyCredential $publicKeyCredential): Authen
7474
7575 return $ response ;
7676 }
77+
78+ /**
79+ * Get credential source from user and public key.
80+ */
81+ protected function getCredentialSource (User $ user , PublicKeyCredential $ publicKeyCredential )
82+ {
83+ $ credentialId = $ publicKeyCredential ->getRawId ();
84+
85+ return (Webauthn::model ())::where ('user_id ' , $ user ->getAuthIdentifier ())
86+ ->where (fn ($ query ) => $ query ->where ('credentialId ' , Base64UrlSafe::encode ($ credentialId ))
87+ ->orWhere ('credentialId ' , Base64UrlSafe::encodeUnpadded ($ credentialId ))
88+ )
89+ ->firstOrFail ()
90+ ->publicKeyCredentialSource ;
91+ }
7792}
0 commit comments