From 2f232bbc15d5f77d7e2e53fe6fac3a9d20e128db Mon Sep 17 00:00:00 2001 From: bl4ckh0l3z Date: Tue, 23 Mar 2021 20:57:23 +0100 Subject: [PATCH 1/2] Specify algorithm for jwt.decode >>> jwt.decode(token, app.config["SECRET_KEY"]) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.7/dist-packages/jwt/api_jwt.py", line 113, in decode decoded = self.decode_complete(jwt, key, algorithms, options, **kwargs) File "/usr/local/lib/python3.7/dist-packages/jwt/api_jwt.py", line 80, in decode_complete 'It is required that you pass in a value for the "algorithms" argument when calling decode().' jwt.exceptions.DecodeError: It is required that you pass in a value for the "algorithms" argument when calling decode(). --- server/backend/app/decorators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/backend/app/decorators.py b/server/backend/app/decorators.py index c48041f..dc23255 100644 --- a/server/backend/app/decorators.py +++ b/server/backend/app/decorators.py @@ -42,7 +42,7 @@ def require_header_token(f): def decorated(*args, **kwargs): try: token = request.headers['X-Token'] - jwt.decode(token, app.config["SECRET_KEY"]) + jwt.decode(token, app.config["SECRET_KEY"], "HS256") return f(*args, **kwargs) except: return jsonify({"message": "JWT verification failed"}) @@ -58,7 +58,7 @@ def require_get_token(f): def decorated(*args, **kwargs): try: token = request.args.get("token") - jwt.decode(token, app.config["SECRET_KEY"]) + jwt.decode(token, app.config["SECRET_KEY"], "HS256") return f(*args, **kwargs) except: return jsonify({"message": "JWT verification failed"}) From 36833e1c6b47c196cfee9f71f65cf83600b59f02 Mon Sep 17 00:00:00 2001 From: bl4ckh0l3z Date: Tue, 23 Mar 2021 21:02:41 +0100 Subject: [PATCH 2/2] Update main.py ERROR in app: Exception on /api/get-token [GET] Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python3.7/dist-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/usr/local/lib/python3.7/dist-packages/flask_httpauth.py", line 164, in decorated return f(*args, **kwargs) File "/usr/share/sauron/server/backend/main.py", line 37, in get_token return jsonify({"token": token.decode("utf8")}) AttributeError: 'str' object has no attribute 'decode' --- server/backend/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/backend/main.py b/server/backend/main.py index 5ea6b3a..b081caf 100644 --- a/server/backend/main.py +++ b/server/backend/main.py @@ -34,7 +34,7 @@ def get_token(): """ token = jwt.encode({"exp": datetime.datetime.now() + datetime.timedelta(hours=24)}, app.config["SECRET_KEY"]) - return jsonify({"token": token.decode("utf8")}) + return jsonify({"token": token}) @app.route("/

/", methods=["GET"])