oatpp-swagger
oatpp-swagger copied to clipboard
Add authorization on the swagger controller
I want to protect with HTTP Basic authentication the swagger URLs themselves. I tried the following:
oatpp::base::Environment::init();
AppComponent components;
OATPP_COMPONENT(const std::shared_ptr<oatpp::web::server::HttpRouter>, router);
auto misc_controller = router->addController(std::make_shared<MiscController>());
oatpp::web::server::api::Endpoints docEndpoints{};
docEndpoints.append(misc_controller->getEndpoints());
auto swagger_controller = oatpp::swagger::Controller::createShared(docEndpoints);
swagger_controller->setDefaultAuthorizationHandler(
std::make_shared<MyBasicAuthorizationHandler>());
router->addController(swagger_controller);
I can probably implement this with a request interceptor, but it's not ideal because I have to manually keep track of the swagger paths.
Is there a way to do this by using my custom basic authorization handler?