|
32 | 32 | useMcp\Server\Authentication\Storage\InMemoryClientRepository; |
33 | 33 | useMcp\Server\Transports\Middleware\CorsMiddleware; |
34 | 34 | useMcp\Server\Transports\Middleware\ProxyAwareMiddleware; |
| 35 | +usePsr\Container\ContainerInterface; |
35 | 36 | useSpiral\Boot\Bootloader\Bootloader; |
36 | 37 | useSpiral\Boot\EnvironmentInterface; |
| 38 | +useSpiral\Config\ConfiguratorInterface; |
37 | 39 | useSpiral\McpServer\MiddlewareRegistryInterface; |
38 | 40 |
|
39 | 41 | finalclass HttpTransportBootloaderextends Bootloader |
40 | 42 | { |
| 43 | +publicfunction__construct( |
| 44 | +privatereadonlyConfiguratorInterface$configurator, |
| 45 | + ) {} |
| 46 | + |
41 | 47 | #[\Override] |
42 | 48 | publicfunctiondefineSingletons():array |
43 | 49 | { |
@@ -177,13 +183,23 @@ public function defineSingletons(): array |
177 | 183 | ]; |
178 | 184 | } |
179 | 185 |
|
| 186 | +publicfunctioninit(EnvironmentInterface$env):void |
| 187 | + { |
| 188 | +$this->configurator->setDefaults(OauthConfig::CONFIG, [ |
| 189 | +'enabled' => (bool)$env->get('OAUTH_ENABLED',false), |
| 190 | +'client_id' =>$env->get('OAUTH_CLIENT_ID'), |
| 191 | +'client_secret' =>$env->get('OAUTH_CLIENT_SECRET'), |
| 192 | + ]); |
| 193 | + } |
| 194 | + |
180 | 195 | publicfunctionboot( |
181 | 196 | MiddlewareRegistryInterface$registry, |
182 | 197 | EnvironmentInterface$env, |
183 | | -McpAuthRouter$oauthRouter, |
184 | 198 | ExceptionHandlerMiddleware$exceptionHandler, |
185 | 199 | LoggerMiddleware$logger, |
186 | 200 | AuthMiddleware$authMiddleware, |
| 201 | +OauthConfig$oauthConfig, |
| 202 | +ContainerInterface$container, |
187 | 203 | ):void { |
188 | 204 | $convertValues =staticfn( |
189 | 205 | string|null|bool$values, |
@@ -212,8 +228,8 @@ public function boot( |
212 | 228 | ); |
213 | 229 |
|
214 | 230 | // Register OAuth router middleware if enabled |
215 | | -if ((bool)$env->get('OAUTH_ENABLED',false)) { |
216 | | -$registry->register($oauthRouter); |
| 231 | +if ($oauthConfig->isEnabled() &&$oauthConfig->hasCredentials()) { |
| 232 | +$registry->register($container->get(McpAuthRouter::class)); |
217 | 233 | } |
218 | 234 |
|
219 | 235 | $registry->register($authMiddleware); |
|