2222use Webauthn\Exception\ AuthenticatorResponseVerificationException ;
2323use Webauthn\ PublicKeyCredential ;
2424use Webauthn\ PublicKeyCredentialRequestOptions ;
25- use Webauthn\ PublicKeyCredentialSource ;
25+ use Webauthn\ CredentialRecord ;
2626use Symfony\Component\Serializer\Exception\ ExceptionInterface as SerializerExceptionInterface ;
2727
2828new # [Title('登入')]
@@ -95,16 +95,20 @@ public function loginWithPasskey(Serializer $serializer): void
9595
9696 $rawId = json_decode ($data [' answer' ], true )[' rawId' ];
9797
98- $passkey = Passkey:: query ()-> where (' credential_id' , $rawId )-> where (' owner_type' , User:: class )-> first ();
98+ $passkey = Passkey:: query ()
99+ -> where (' credential_id' , $rawId )
100+ -> where (' owner_type' , User:: class )
101+ -> first ();
102+
99103
100104 if (! $passkey ) {
101105 $this -> dispatch (' toast' , status : ' danger' , message : ' 密碼金鑰無效' );
102106
103107 return ;
104108 }
105109
106- $publicKeyCredentialSource = $serializer -> fromJson (json_encode ($passkey -> data ),
107- PublicKeyCredentialSource :: class );
110+ $credentialRecord = $serializer -> fromJson (json_encode ($passkey -> data ),
111+ CredentialRecord :: class );
108112
109113 $options = Session:: get (' passkey-authentication-options' );
110114
@@ -117,21 +121,23 @@ public function loginWithPasskey(Serializer $serializer): void
117121 $publicKeyCredentialRequestOptions = $serializer -> fromJson ($options ,
118122 PublicKeyCredentialRequestOptions:: class );
119123
120- AuthenticatorAssertionResponseValidator:: create (new CeremonyStepManagerFactory ()-> requestCeremony ())
121- -> check (
122- publicKeyCredentialSource : $publicKeyCredentialSource ,
123- authenticatorAssertionResponse : $publicKeyCredential -> response ,
124- publicKeyCredentialRequestOptions : $publicKeyCredentialRequestOptions ,
125- host : request ()-> getHost (),
126- userHandle : null
127- );
124+ $credentialRecord = AuthenticatorAssertionResponseValidator:: create (
125+ new CeremonyStepManagerFactory ()-> requestCeremony ()
126+ )-> check (
127+ credentialRecord : $credentialRecord ,
128+ authenticatorAssertionResponse : $publicKeyCredential -> response ,
129+ publicKeyCredentialRequestOptions : $publicKeyCredentialRequestOptions ,
130+ host : request ()-> getHost (),
131+ userHandle : null
132+ );
128133 } catch (SerializerExceptionInterface|AuthenticatorResponseVerificationException) {
129134 $this -> dispatch (' toast' , status : ' danger' , message : ' 密碼金鑰無效' );
130135
131136 return ;
132137 }
133138
134139 $passkey -> update ([
140+ ' data' => $serializer -> toArray ($credentialRecord ),
135141 ' last_used_at' => now (),
136142 ]);
137143
0 commit comments