flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

Add authentication to swagger-UI static components

Open matt-carr opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe.

When a flask-restx application is deployed behind an authenticated reverse proxy (in my case, Kong Ingress on kubernetes), there's no way to let the swagger UI know "hey, add this querystring/these params to your requests to static resources." Query params/headers can be added to load up the root swagger UI page, but its requests for CSS/JS/swagger.json files will fail because they don't include those same parameters.

Describe the solution you'd like

Some ability to configure swagger-ui to attach authentication data to its requests to its owned docs, e.g. a SWAGGER_UI_AUTH_HEADER/SWAGGER_UI_AUTH_QUERY_PARAM flask config that will indicate to the swagger templates where the auth information is located so it can append it to the static file requests

Describe alternatives you've considered

Right now, given that we're on k8s and swagger-UI is a dev resource, we're just port-forwarding to the appropriate pod.

I guess you could probably add a config option that embedded the static resources in the swagger-ui html so that you only have to authenticate with swagger.json?

matt-carr avatar Jun 29 '21 12:06 matt-carr

Imho you want to tackle the auth issue at the wsgi level.

zogzog avatar Dec 14 '21 17:12 zogzog