From c7d47fee9cdb3a1ec959ffd09ad1688506b49943 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 4 May 2021 12:14:25 -0400 Subject: [PATCH] island: Extract method _create_access_token() from _get_credentials_from_request() --- monkey/monkey_island/cc/resources/auth/auth.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/monkey/monkey_island/cc/resources/auth/auth.py b/monkey/monkey_island/cc/resources/auth/auth.py index a6f395424..d04b94da4 100644 --- a/monkey/monkey_island/cc/resources/auth/auth.py +++ b/monkey/monkey_island/cc/resources/auth/auth.py @@ -41,12 +41,7 @@ class Authenticate(flask_restful.Resource): (username, password) = Authenticate._get_credentials_from_request(request) if self._credentials_match_registered_user(username, password): - access_token = flask_jwt_extended.create_access_token( - identity=user_store.UserStore.username_table[username].id - ) - logger.debug( - f"Created access token for user {username} that begins with {access_token[:4]}" - ) + access_token = Authenticate._create_access_token(username) return make_response({"access_token": access_token, "error": ""}, 200) else: return make_response({"error": "Invalid credentials"}, 401) @@ -68,6 +63,17 @@ class Authenticate(flask_restful.Resource): return False + @staticmethod + def _create_access_token(username): + access_token = flask_jwt_extended.create_access_token( + identity=user_store.UserStore.username_table[username].id + ) + logger.debug( + f"Created access token for user {username} that begins with {access_token[:4]}" + ) + + return access_token + # See https://flask-jwt-extended.readthedocs.io/en/stable/custom_decorators/ def jwt_required(fn):