From c66a97e1816c3a581e91f57902e80917ac596e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Garc=C3=ADa?= Date: Mon, 26 Nov 2018 15:41:02 +0100 Subject: [PATCH] Fixes bug setting expiration period for token. --- flask_graphql_auth/main.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/flask_graphql_auth/main.py b/flask_graphql_auth/main.py index 4f70af2..d6ef2b3 100644 --- a/flask_graphql_auth/main.py +++ b/flask_graphql_auth/main.py @@ -68,13 +68,17 @@ def _create_basic_token_data(identity, token_type): } if token_type == "refresh": - token_data.update({ - "exp": current_app.config['JWT_REFRESH_TOKEN_EXPIRES'] - }) + exp = current_app.config['JWT_REFRESH_TOKEN_EXPIRES'] + if isinstance(exp, int): + exp = datetime.timedelta(days=exp) else: - token_data.update({ - "exp": current_app.config['JWT_ACCESS_TOKEN_EXPIRES'] - }) + exp = current_app.config['JWT_ACCESS_TOKEN_EXPIRES'] + if isinstance(exp, int): + exp = datetime.timedelta(minutes=exp) + + token_data.update({ + "exp": now + exp + }) return token_data @@ -113,4 +117,3 @@ def _create_refresh_token(self, identity, user_claims): json_encoder=current_app.json_encoder).decode('utf-8') return encoded_token -