Closed 0coolcard0 closed 1 year ago
You can do it via jwt_required()(protected)
. See: https://stackoverflow.com/questions/21441100/manually-calling-a-decorator-that-takes-arguments
I do wonder why you are doing this though? It feels like using either the decorator (@jwt_required()
) or calling verify_jwt_in_request()
directly in your function would be easier.
I wanted to make the authentication method different depending on the version of the currently running app, so I wanted to call jwt_required directly. However, when calling directly, typeerror occurred due to arguments problem. I don't think it's good to call and use the decorator directly. I will use verify_jwt_in_request as per your guide. Thanks for the reply.
jwt_required(func(arg)) Previously, in version 3.x, it was called and used as above.
A TypeError occurred in version 4.4.4. -> Traceback (most recent call last): File "/Users/user/PycharmProjects/flaskTestProject/venv/lib/python3.8/site-packages/flask/app.py", line 2525, in wsgi_app response = self.full_dispatch_request() File "/Users/user/PycharmProjects/flaskTestProject/venv/lib/python3.8/site-packages/flask/app.py", line 1823, in full_dispatch_request return self.finalize_request(rv) File "/Users/user/PycharmProjects/flaskTestProject/venv/lib/python3.8/site-packages/flask/app.py", line 1842, in finalize_request response = self.make_response(rv) File "/Users/user/PycharmProjects/flaskTestProject/venv/lib/python3.8/site-packages/flask/app.py", line 2162, in make_response raise TypeError( File "/Users/user/PycharmProjects/flaskTestProject/venv/lib/python3.8/site-packages/flask/app.py", line 2158, in make_response rv = self.response_class.force_type( File "/Users/user/PycharmProjects/flaskTestProject/venv/lib/python3.8/site-packages/werkzeug/wrappers/response.py", line 268, in force_type response = Response(*run_wsgi_app(response, environ)) File "/Users/user/PycharmProjects/flaskTestProject/venv/lib/python3.8/site-packages/werkzeug/test.py", line 1242, in run_wsgi_app app_rv = app(environ, start_response) TypeError: wrapper() takes 1 positional argument but 2 were given
How should I call it in version 4.4.4? https://github.com/vimalloc/flask-jwt-extended/blob/88a628ec88eb3c0e766300613a1367ac3eb3f34f/flask_jwt_extended/view_decorators.py#L112-L158