Use authorization in swagger UI for flask endpoint (flasgger)

20 views Asked by At

I want to use swagger ui (generated via flasggers docstrings) to test my jwt protected flask routes.

I have registered a blueprint with my flask app in the init.py

app = Flask(__name__)
app.register_blueprint(routes.bp)
Swagger(app)

In a routes.py file, I am defining routes, some of them require a jwt token

@bp.route("/new_analysis", methods=["POST"])
@cross_origin(supports_credentials=True)
@app_helpers.token_required(current_app)

Together with the frontend, these routes work fine.

Now, I want to use flasgger to write docstrings to each route to test them with swagger ui.

def start_analysis():
"""
Description'
---
tags:
  - Analysis
consumes:
  - application/json
security:
  - BearerAuth: []

Now, in the swagger ui, the route appears with the lock icon, however, I am not prompted to enter the token. I read that flasgger only supports OpenApi 3.0 experimentally, which would imply that bearer auth is probably not working (https://swagger.io/docs/specification/authentication/bearer-authentication/) ?

Edit: When I am executing the request via swagger ui, I get "Token missing", which comes surely from the wrapper function token_required, so I can savely that, no token is sent.

Cheers

0

There are 0 answers