2424use LaravelWebauthn \Contracts \RegisterSuccessResponse as RegisterSuccessResponseContract ;
2525use LaravelWebauthn \Contracts \RegisterViewResponse as RegisterViewResponseContract ;
2626use LaravelWebauthn \Contracts \UpdateResponse as UpdateResponseContract ;
27+ use LaravelWebauthn \Events \EventDispatcher ;
2728use LaravelWebauthn \Facades \Webauthn as WebauthnFacade ;
2829use LaravelWebauthn \Http \Responses \DestroyResponse ;
2930use LaravelWebauthn \Http \Responses \FailedKeyConfirmedResponse ;
5859use Webauthn \CeremonyStep \CeremonyStepManagerFactory ;
5960use Webauthn \Counter \CounterChecker ;
6061use Webauthn \Counter \ThrowExceptionIfInvalid ;
62+ use Webauthn \Event \CanDispatchEvents ;
63+ use Webauthn \MetadataService \CanLogData ;
6164use Webauthn \PublicKeyCredentialRpEntity ;
6265
6366/**
@@ -82,6 +85,8 @@ public function boot(): void
8285 #[\Override]
8386 public function register (): void
8487 {
88+ $ this ->app ->bind ('webauthn.log ' , fn ($ app ) => $ app ['log ' ]->channel (config ('webauthn.log ' , config ('logging.default ' ))));
89+
8590 $ this ->app ->singleton (WebauthnFacade::class, Webauthn::class);
8691
8792 $ this ->registerResponseBindings ();
@@ -93,7 +98,6 @@ public function register(): void
9398 );
9499
95100 $ this ->app ->bind (StatefulGuard::class, fn () => Auth::guard (config ('webauthn.guard ' , null )));
96- $ this ->app ->bind ('webauthn.log ' , fn ($ app ) => $ app ['log ' ]->channel (config ('webauthn.log ' , config ('logging.default ' ))));
97101 }
98102
99103 /**
@@ -132,6 +136,10 @@ public function registerResponseBindings(): void
132136 */
133137 protected function bindWebAuthnPackage (): void
134138 {
139+ $ this ->app ->singleton (EventDispatcher::class);
140+ $ this ->app ->resolving (CanDispatchEvents::class, fn (CanDispatchEvents $ object ) => $ object ->setEventDispatcher ($ this ->app [EventDispatcher::class]));
141+ $ this ->app ->resolving (CanLogData::class, fn (CanLogData $ object ) => $ object ->setLogger ($ this ->app ['webauthn.log ' ]));
142+
135143 $ this ->app ->bind (
136144 PackedAttestationStatementSupport::class,
137145 fn ($ app ) => new PackedAttestationStatementSupport (
@@ -141,60 +149,69 @@ protected function bindWebAuthnPackage(): void
141149 $ this ->app ->bind (
142150 AttestationStatementSupportManager::class,
143151 fn ($ app ) => tap (new AttestationStatementSupportManager , function ($ manager ) use ($ app ) {
144- // https://www.w3.org/TR/webauthn/#sctn-none-attestation
145- $ manager -> add ( $ app [NoneAttestationStatementSupport::class]);
146-
147- // https://www.w3.org/TR/webauthn/#sctn-fido-u2f -attestation
148- $ manager -> add ( $ app [FidoU2FAttestationStatementSupport ::class]);
149-
150- // https://www.w3.org/TR/webauthn/#sctn-android-key-attestation
151- $ manager -> add ( $ app [AndroidKeyAttestationStatementSupport::class]);
152-
153- // https://www.w3.org/TR/webauthn/#sctn-tpm -attestation
154- $ manager -> add ( $ app [TPMAttestationStatementSupport ::class]);
155-
156- // https://www.w3.org/TR/webauthn/#sctn-packed-attestation
157- $ manager -> add ( $ app [PackedAttestationStatementSupport::class]) ;
158-
159- // https://www.w3.org/TR/webauthn/#sctn-apple-anonymous-attestation
160- $ manager -> add ( $ app [AppleAttestationStatementSupport::class]);
152+ $ supports = [
153+ // https://www.w3.org/TR/webauthn/#sctn-packed-attestation
154+ PackedAttestationStatementSupport::class,
155+ // https://www.w3.org/TR/webauthn/#sctn-tpm -attestation
156+ TPMAttestationStatementSupport ::class,
157+ // https://www.w3.org/TR/webauthn/#sctn-android-key-attestation
158+ AndroidKeyAttestationStatementSupport::class,
159+ // https://www.w3.org/TR/webauthn/#sctn-fido-u2f-attestation
160+ FidoU2FAttestationStatementSupport::class,
161+ // https://www.w3.org/TR/webauthn/#sctn-none -attestation
162+ NoneAttestationStatementSupport ::class,
163+ // https://www.w3.org/TR/webauthn/#sctn-apple-anonymous-attestation
164+ AppleAttestationStatementSupport::class,
165+ ] ;
166+ foreach ( $ supports as $ support ) {
167+ $ manager -> add ( $ app [ $ support ]);
168+ }
161169 })
162170 );
163171 $ this ->app ->bind (
164172 AttestationObjectLoader::class,
165- fn ($ app ) => tap (new AttestationObjectLoader (
166- $ app [AttestationStatementSupportManager::class]
167- ), fn (AttestationObjectLoader $ loader ) => $ loader ->setLogger ($ app ['webauthn.log ' ])
173+ fn ($ app ) => new AttestationObjectLoader (
174+ attestationStatementSupportManager: $ app [AttestationStatementSupportManager::class]
168175 )
169176 );
170-
171177 $ this ->app ->bind (
172- CounterChecker ::class,
173- fn ($ app ) => new ThrowExceptionIfInvalid ($ app [' webauthn.log ' ] )
178+ SerializerInterface ::class,
179+ fn ($ app ) => ( new \ Webauthn \ Denormalizer \ WebauthnSerializerFactory ($ app [AttestationStatementSupportManager::class]))-> create ( )
174180 );
175181
176182 $ this ->app ->bind (
177- AuthenticatorAttestationResponseValidator::class,
178- fn ($ app ) => tap (new AuthenticatorAttestationResponseValidator (
179- ceremonyStepManager: ($ app [CeremonyStepManagerFactory::class])->creationCeremony (),
180- ), fn (AuthenticatorAttestationResponseValidator $ responseValidator ) => $ responseValidator ->setLogger ($ app ['webauthn.log ' ])
183+ CounterChecker::class,
184+ fn ($ app ) => new ThrowExceptionIfInvalid (
185+ logger: $ app ['webauthn.log ' ]
181186 )
182187 );
188+
183189 $ this ->app ->bind (
184190 CeremonyStepManagerFactory::class,
185191 fn ($ app ) => tap (new CeremonyStepManagerFactory , function (CeremonyStepManagerFactory $ factory ) use ($ app ) {
186192 $ factory ->setExtensionOutputCheckerHandler ($ app [ExtensionOutputCheckerHandler::class]);
187193 $ factory ->setAlgorithmManager ($ app [CoseAlgorithmManager::class]);
188194 $ factory ->setCounterChecker ($ app [CounterChecker::class]);
195+ $ factory ->setAttestationStatementSupportManager ($ app [AttestationStatementSupportManager::class]);
196+ // $factory->setAllowedOrigins(
197+ // allowedOrigins: $app['config']->get('webauthn.allowed_origins'),
198+ // allowSubdomains: $app['config']->get('webauthn.allow_subdomains')
199+ // );
189200 })
190201 );
202+ $ this ->app ->bind (
203+ AuthenticatorAttestationResponseValidator::class,
204+ fn ($ app ) => new AuthenticatorAttestationResponseValidator (
205+ ceremonyStepManager: ($ app [CeremonyStepManagerFactory::class])->creationCeremony (),
206+ )
207+ );
191208 $ this ->app ->bind (
192209 AuthenticatorAssertionResponseValidator::class,
193- fn ($ app ) => tap ( (new AuthenticatorAssertionResponseValidator (
210+ fn ($ app ) => (new AuthenticatorAssertionResponseValidator (
194211 ceremonyStepManager: ($ app [CeremonyStepManagerFactory::class])->requestCeremony ()
195- )), fn (AuthenticatorAssertionResponseValidator $ responseValidator ) => $ responseValidator ->setLogger ($ app ['webauthn.log ' ])
196- )
212+ ))
197213 );
214+
198215 $ this ->app ->bind (
199216 AuthenticatorSelectionCriteria::class,
200217 fn ($ app ) => new AuthenticatorSelectionCriteria (
@@ -203,6 +220,7 @@ protected function bindWebAuthnPackage(): void
203220 residentKey: $ app ['config ' ]->get ('webauthn.resident_key ' , 'preferred ' )
204221 )
205222 );
223+
206224 $ this ->app ->bind (
207225 PublicKeyCredentialRpEntity::class,
208226 fn ($ app ) => new PublicKeyCredentialRpEntity (
@@ -211,6 +229,7 @@ protected function bindWebAuthnPackage(): void
211229 icon: $ app ['config ' ]->get ('webauthn.icon ' )
212230 )
213231 );
232+
214233 $ this ->app ->bind (
215234 CoseAlgorithmManager::class,
216235 fn ($ app ) => $ app [CoseAlgorithmManagerFactory::class]
@@ -243,10 +262,6 @@ protected function bindWebAuthnPackage(): void
243262 }
244263 })
245264 );
246- $ this ->app ->bind (
247- SerializerInterface::class,
248- fn ($ app ) => (new \Webauthn \Denormalizer \WebauthnSerializerFactory ($ app [AttestationStatementSupportManager::class]))->create ()
249- );
250265 }
251266
252267 /**
0 commit comments