Protecting flassger route with JWT

38 Views Asked by At

To understand how it works I have written a Flask program with the /login and /renew routes to obtain and refresh a JWT token.

I also defined a decorator function '@tokenrec' which I use to protect my functional endpoints such as:

@app.route("/protected", methods=["GET"])
@tokenreq
def protected_route():
"""simple protected route"""
return jsonify({"message": "You have access to this JWT protected resource."})

so unless I do have my JWT I will get an error when accessing /protected

I then added flasgger and related docstring documentation so now if I go to the /apidocs route I get the swagger page.

Is there a way to protect the /apidocs rount with my '@tokenreq' decorator so that it will be shown only to users that have obtained their JWT token?

Thank you

0

There are 0 best solutions below