Search code examples
pythonflaskswagger

No adding of token in swagger for flask


This is my code:

authorizations = {
    'Basic Auth': {
        'type': 'basic',
        'in': 'header',
        'name': 'Authorization'
    },
}
task_namespace = Namespace('task', security='Authorization', authorizations=authorizations, description='A namespace for tasks')
@task_namespace.route('/')
class TaskGetResource(Resource):
    @jwt_required(refresh=True)
    def get(self):
        user_id = get_jwt_identity()
        return Task.query.filter_by(
                user_id=user_id
            )

WHen I run the flask app and go to the swagger url, I authorize it by email and password and then run the api/task as located in the swagger, but the header token does not get added

Complete code is https://github.com/eadaradhiraj/flask-tasks-jwt

enter image description here


Solution

  • I changed the the code as follows after going through this video:

    authorizations = {
    'jsonWebToken': {
        'type': 'apiKey',
        'in': 'header',
        'name': 'Authorization'
    },
    }
    task_namespace = Namespace(
        'task',
        authorizations=authorizations
    )
    
    @task_namespace.route('/')
    class TaskGetResource(Resource):
        @task_namespace.doc(security="jsonWebToken")
        @jwt_required()
        def get(self):
            ....