Merge pull request #62 from bl4ckh0l3z/main
Fix for JWT token generation and validation
This commit is contained in:
commit
f1250a00ba
@ -42,7 +42,7 @@ def require_header_token(f):
|
|||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
token = request.headers['X-Token']
|
token = request.headers['X-Token']
|
||||||
jwt.decode(token, app.config["SECRET_KEY"])
|
jwt.decode(token, app.config["SECRET_KEY"], "HS256")
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
except:
|
except:
|
||||||
return jsonify({"message": "JWT verification failed"})
|
return jsonify({"message": "JWT verification failed"})
|
||||||
@ -58,7 +58,7 @@ def require_get_token(f):
|
|||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
token = request.args.get("token")
|
token = request.args.get("token")
|
||||||
jwt.decode(token, app.config["SECRET_KEY"])
|
jwt.decode(token, app.config["SECRET_KEY"], "HS256")
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
except:
|
except:
|
||||||
return jsonify({"message": "JWT verification failed"})
|
return jsonify({"message": "JWT verification failed"})
|
||||||
|
@ -34,7 +34,7 @@ def get_token():
|
|||||||
"""
|
"""
|
||||||
token = jwt.encode({"exp": datetime.datetime.now() +
|
token = jwt.encode({"exp": datetime.datetime.now() +
|
||||||
datetime.timedelta(hours=24)}, app.config["SECRET_KEY"])
|
datetime.timedelta(hours=24)}, app.config["SECRET_KEY"])
|
||||||
return jsonify({"token": token.decode("utf8")})
|
return jsonify({"token": token})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/<p>/<path:path>", methods=["GET"])
|
@app.route("/<p>/<path:path>", methods=["GET"])
|
||||||
|
Loading…
Reference in New Issue
Block a user