diff --git a/src/Laravel/ApiPlatformProvider.php b/src/Laravel/ApiPlatformProvider.php index 544980fa9bb..e814c359bc3 100644 --- a/src/Laravel/ApiPlatformProvider.php +++ b/src/Laravel/ApiPlatformProvider.php @@ -705,7 +705,33 @@ public function register(): void /** @var ConfigRepository */ $config = $app['config']; - return new Options(title: $config->get('api-platform.title') ?? ''); + return new Options( + title: $config->get('api-platform.title', ''), + description: $config->get('api-platform.description', ''), + version: $config->get('api-platform.version', ''), + oAuthEnabled: $config->get('api-platform.swagger_ui.oauth.enabled', false), + oAuthType: $config->get('api-platform.swagger_ui.oauth.type', null), + oAuthFlow: $config->get('api-platform.swagger_ui.oauth.flow', null), + oAuthTokenUrl: $config->get('api-platform.swagger_ui.oauth.tokenUrl', null), + oAuthAuthorizationUrl: $config->get('api-platform.swagger_ui.oauth.authorizationUrl', null), + oAuthRefreshUrl: $config->get('api-platform.swagger_ui.oauth.refreshUrl', null), + oAuthScopes: $config->get('api-platform.swagger_ui.oauth.scopes', []), + apiKeys: $config->get('api-platform.swagger_ui.apiKeys', []), + ); + }); + + $this->app->singleton(SwaggerUiProcessor::class, function (Application $app) { + /** @var ConfigRepository */ + $config = $app['config']; + + return new SwaggerUiProcessor( + urlGenerator: $app->make(UrlGeneratorInterface::class), + normalizer: $app->make(NormalizerInterface::class), + openApiOptions: $app->make(Options::class), + oauthClientId: $config->get('api-platform.swagger_ui.oauth.clientId'), + oauthClientSecret: $config->get('api-platform.swagger_ui.oauth.clientSecret'), + oauthPkce: $config->get('api-platform.swagger_ui.oauth.pkce', false), + ); }); $this->app->singleton(DocumentationController::class, function (Application $app) { diff --git a/src/Laravel/State/SwaggerUiProcessor.php b/src/Laravel/State/SwaggerUiProcessor.php index a09cb213240..6a90a23fdc9 100644 --- a/src/Laravel/State/SwaggerUiProcessor.php +++ b/src/Laravel/State/SwaggerUiProcessor.php @@ -70,6 +70,7 @@ public function process(mixed $openApi, Operation $operation, array $uriVariable 'flow' => $this->openApiOptions->getOAuthFlow(), 'tokenUrl' => $this->openApiOptions->getOAuthTokenUrl(), 'authorizationUrl' => $this->openApiOptions->getOAuthAuthorizationUrl(), + 'redirectUrl' => $request->getSchemeAndHttpHost().'/vendor/api-platform/swagger-ui/oauth2-redirect.html', 'scopes' => $this->openApiOptions->getOAuthScopes(), 'clientId' => $this->oauthClientId, 'clientSecret' => $this->oauthClientSecret, diff --git a/src/Laravel/config/api-platform.php b/src/Laravel/config/api-platform.php index 29bad029740..3a0d221a19e 100644 --- a/src/Laravel/config/api-platform.php +++ b/src/Laravel/config/api-platform.php @@ -72,7 +72,24 @@ ], 'swagger_ui' => [ - 'enabled' => true + 'enabled' => true, + //'apiKeys' => [ + // 'api' => [ + // 'type' => 'Bearer', + // 'name' => 'Authentication Token', + // 'in' => 'header' + // ] + //], + //'oauth' => [ + // 'enabled' => true, + // 'type' => 'oauth2', + // 'flow' => 'authorizationCode', + // 'tokenUrl' => '', + // 'authorizationUrl' =>'', + // 'refreshUrl' => '', + // 'scopes' => ['scope1' => 'Description scope 1'], + // 'pkce' => true + //] ], 'url_generation_strategy' => UrlGeneratorInterface::ABS_PATH,