I'm using eve_swagger (https://github.com/pyeve/eve-swagger) in a project and it works great for generating swagger docs. I have a use case where I need to have the default /api-docs
endpoint that is created as a route in the library require authentication.
When I create my eve app, I set the auth
param to my auth class, but /api-docs endpoint is created with a blueprint and I'm not sure how I can add auth to this endpoint. Any ideas?
My eve* deps:
eve = "~0.7"
eve_sqlalchemy = "~0.7"
eve_swagger = "^0.0.11"
Thanks!
I found a way, not sure if this is the best/right way though.
I take the eve_swagger blueprint that's provided, and add a before_request with an authorization function. Something "like" this:
import eve_swagger
from flask import current_app as app
def authorize_swagger:
# my auth logic
eve_swagger.swagger.before_request(authorize_swagger)
app.register_blueprint(eve_swagger.swagger)
The result of doing this is now when I call the default /api-docs
route, my authorization function is called and processed before the request. This way if my function decides the request is not authorized, it can stop the request.