@@ -30,7 +30,7 @@ public function __construct(
3030 *
3131 * @throws ResponseMismatchException
3232 */
33- public function __invoke (User $ user , array $ data ): bool
33+ public function __invoke (? User $ user , array $ data ): bool
3434 {
3535 // Load the data
3636 $ content = json_encode ($ data , flags: JSON_THROW_ON_ERROR );
@@ -51,11 +51,15 @@ public function __invoke(User $user, array $data): bool
5151 /**
5252 * Get public Key credential.
5353 */
54- protected function pullPublicKey (User $ user ): PublicKeyCredentialRequestOptions
54+ protected function pullPublicKey (? User $ user ): PublicKeyCredentialRequestOptions
5555 {
5656 try {
5757 $ value = $ this ->cache ->pull ($ this ->cacheKey ($ user ));
5858
59+ if ($ value === null && in_array (config ('webauthn.userless ' ), ['required ' , 'preferred ' ], true )) {
60+ $ value = $ this ->cache ->pull ($ this ->cacheKey (null ));
61+ }
62+
5963 return $ this ->loader ->deserialize ($ value , PublicKeyCredentialRequestOptions::class, 'json ' );
6064 } catch (\Exception $ e ) {
6165 app ('webauthn.log ' )->debug ('Webauthn publickKey deserialize error ' , ['exception ' => $ e ]);
@@ -79,14 +83,16 @@ protected function getResponse(PublicKeyCredential $publicKeyCredential): Authen
7983 /**
8084 * Get credential source from user and public key.
8185 */
82- protected function getCredentialSource (User $ user , PublicKeyCredential $ publicKeyCredential )
86+ protected function getCredentialSource (? User $ user , PublicKeyCredential $ publicKeyCredential )
8387 {
8488 $ credentialId = $ publicKeyCredential ->rawId ;
8589
86- return (Webauthn::model ())::where (' user_id ' , $ user -> getAuthIdentifier ())
87- -> where ( fn ($ query ) => $ query ->where ('credentialId ' , Base64UrlSafe::encode ($ credentialId ))
90+ return (Webauthn::model ())::where (
91+ fn ($ query ) => $ query ->where ('credentialId ' , Base64UrlSafe::encode ($ credentialId ))
8892 ->orWhere ('credentialId ' , Base64UrlSafe::encodeUnpadded ($ credentialId ))
89- )
93+ )->where (
94+ fn ($ query ) => $ user !== null ? $ query ->where ('user_id ' , $ user ->getAuthIdentifier ()) : $ query
95+ )
9096 ->firstOrFail ()
9197 ->publicKeyCredentialSource ;
9298 }
0 commit comments