forked from p15670423/monkey
island: Extract method _create_access_token() from _get_credentials_from_request()
This commit is contained in:
parent
a8646fc056
commit
c7d47fee9c
|
@ -41,12 +41,7 @@ class Authenticate(flask_restful.Resource):
|
||||||
(username, password) = Authenticate._get_credentials_from_request(request)
|
(username, password) = Authenticate._get_credentials_from_request(request)
|
||||||
|
|
||||||
if self._credentials_match_registered_user(username, password):
|
if self._credentials_match_registered_user(username, password):
|
||||||
access_token = flask_jwt_extended.create_access_token(
|
access_token = Authenticate._create_access_token(username)
|
||||||
identity=user_store.UserStore.username_table[username].id
|
|
||||||
)
|
|
||||||
logger.debug(
|
|
||||||
f"Created access token for user {username} that begins with {access_token[:4]}"
|
|
||||||
)
|
|
||||||
return make_response({"access_token": access_token, "error": ""}, 200)
|
return make_response({"access_token": access_token, "error": ""}, 200)
|
||||||
else:
|
else:
|
||||||
return make_response({"error": "Invalid credentials"}, 401)
|
return make_response({"error": "Invalid credentials"}, 401)
|
||||||
|
@ -68,6 +63,17 @@ class Authenticate(flask_restful.Resource):
|
||||||
|
|
||||||
return False
|
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/
|
# See https://flask-jwt-extended.readthedocs.io/en/stable/custom_decorators/
|
||||||
def jwt_required(fn):
|
def jwt_required(fn):
|
||||||
|
|
Loading…
Reference in New Issue