3535use LaravelWebauthn \Http \Responses \RegisterViewResponse ;
3636use LaravelWebauthn \Http \Responses \UpdateResponse ;
3737use LaravelWebauthn \Services \Webauthn ;
38+ use Psr \EventDispatcher \EventDispatcherInterface ;
3839use Psr \Http \Client \ClientInterface ;
3940use Psr \Http \Message \RequestFactoryInterface ;
4041use Psr \Http \Message \ResponseFactoryInterface ;
4647use Symfony \Component \Serializer \SerializerInterface ;
4748use Webauthn \AttestationStatement \AndroidKeyAttestationStatementSupport ;
4849use Webauthn \AttestationStatement \AppleAttestationStatementSupport ;
49- use Webauthn \AttestationStatement \AttestationObjectLoader ;
5050use Webauthn \AttestationStatement \AttestationStatementSupportManager ;
5151use Webauthn \AttestationStatement \FidoU2FAttestationStatementSupport ;
5252use Webauthn \AttestationStatement \NoneAttestationStatementSupport ;
6868 */
6969class WebauthnServiceProvider extends ServiceProvider
7070{
71+ /**
72+ * All of the container singletons that should be registered.
73+ *
74+ * @var array
75+ */
76+ public $ singletons = [
77+ WebauthnFacade::class => Webauthn::class,
78+ DestroyResponseContract::class => DestroyResponse::class,
79+ LoginSuccessResponseContract::class => LoginSuccessResponse::class,
80+ LoginViewResponseContract::class => LoginViewResponse::class,
81+ RegisterSuccessResponseContract::class => RegisterSuccessResponse::class,
82+ RegisterViewResponseContract::class => RegisterViewResponse::class,
83+ UpdateResponseContract::class => UpdateResponse::class,
84+ KeyConfirmedResponseContract::class => KeyConfirmedResponse::class,
85+ FailedKeyConfirmedResponseContract::class => FailedKeyConfirmedResponse::class,
86+ EventDispatcherInterface::class => EventDispatcher::class,
87+ ];
88+
7189 /**
7290 * Bootstrap any application services.
7391 */
@@ -85,18 +103,14 @@ public function boot(): void
85103 #[\Override]
86104 public function register (): void
87105 {
88- $ this ->app ->bind ('webauthn.log ' , fn ($ app ) => $ app ['log ' ]->channel (config ('webauthn.log ' , config ('logging.default ' ))));
89-
90- $ this ->app ->singleton (WebauthnFacade::class, Webauthn::class);
91-
92- $ this ->registerResponseBindings ();
93106 $ this ->bindWebAuthnPackage ();
94107 $ this ->bindPsrInterfaces ();
95108
96109 $ this ->mergeConfigFrom (
97110 __DIR__ .'/../config/webauthn.php ' , 'webauthn '
98111 );
99112
113+ $ this ->app ->bind ('webauthn.log ' , fn ($ app ) => $ app ['log ' ]->channel (config ('webauthn.log ' , config ('logging.default ' ))));
100114 $ this ->app ->bind (StatefulGuard::class, fn () => Auth::guard (config ('webauthn.guard ' , null )));
101115 }
102116
@@ -116,36 +130,14 @@ private function configureRoutes(): void
116130 }
117131 }
118132
119- /**
120- * Register the response bindings.
121- */
122- public function registerResponseBindings (): void
123- {
124- $ this ->app ->singleton (DestroyResponseContract::class, DestroyResponse::class);
125- $ this ->app ->singleton (LoginSuccessResponseContract::class, LoginSuccessResponse::class);
126- $ this ->app ->singleton (LoginViewResponseContract::class, LoginViewResponse::class);
127- $ this ->app ->singleton (RegisterSuccessResponseContract::class, RegisterSuccessResponse::class);
128- $ this ->app ->singleton (RegisterViewResponseContract::class, RegisterViewResponse::class);
129- $ this ->app ->singleton (UpdateResponseContract::class, UpdateResponse::class);
130- $ this ->app ->singleton (KeyConfirmedResponseContract::class, KeyConfirmedResponse::class);
131- $ this ->app ->singleton (FailedKeyConfirmedResponseContract::class, FailedKeyConfirmedResponse::class);
132- }
133-
134133 /**
135134 * Bind all the WebAuthn package services to the Service Container.
136135 */
137136 protected function bindWebAuthnPackage (): void
138137 {
139- $ this ->app ->singleton (EventDispatcher::class);
140- $ this ->app ->resolving (CanDispatchEvents::class, fn (CanDispatchEvents $ object ) => $ object ->setEventDispatcher ($ this ->app [EventDispatcher::class]));
138+ $ this ->app ->resolving (CanDispatchEvents::class, fn (CanDispatchEvents $ object ) => $ object ->setEventDispatcher ($ this ->app [EventDispatcherInterface::class]));
141139 $ this ->app ->resolving (CanLogData::class, fn (CanLogData $ object ) => $ object ->setLogger ($ this ->app ['webauthn.log ' ]));
142140
143- $ this ->app ->bind (
144- PackedAttestationStatementSupport::class,
145- fn ($ app ) => new PackedAttestationStatementSupport (
146- algorithmManager: $ app [CoseAlgorithmManager::class]
147- )
148- );
149141 $ this ->app ->bind (
150142 AttestationStatementSupportManager::class,
151143 fn ($ app ) => tap (new AttestationStatementSupportManager , function ($ manager ) use ($ app ) {
@@ -168,12 +160,6 @@ protected function bindWebAuthnPackage(): void
168160 }
169161 })
170162 );
171- $ this ->app ->bind (
172- AttestationObjectLoader::class,
173- fn ($ app ) => new AttestationObjectLoader (
174- attestationStatementSupportManager: $ app [AttestationStatementSupportManager::class]
175- )
176- );
177163 $ this ->app ->bind (
178164 SerializerInterface::class,
179165 fn ($ app ) => (new \Webauthn \Denormalizer \WebauthnSerializerFactory ($ app [AttestationStatementSupportManager::class]))->create ()
0 commit comments