From 990a6e70e27faa122879eb89fb3da588f831ccd3 Mon Sep 17 00:00:00 2001
From: Martin Weise <martin.weise@tuwien.ac.at>
Date: Mon, 1 May 2023 22:06:36 +0200
Subject: [PATCH] Added flask jwt endoint authentication

---
 dbrepo-semantics-service/app.py           | 6 +++++-
 dbrepo-semantics-service/requirements.txt | 3 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/dbrepo-semantics-service/app.py b/dbrepo-semantics-service/app.py
index 573e74fbf6..70dceff24e 100644
--- a/dbrepo-semantics-service/app.py
+++ b/dbrepo-semantics-service/app.py
@@ -13,6 +13,7 @@ from gevent.pywsgi import WSGIServer
 from save import insert_mdb_concepts, insert_mdb_units
 from onto_feat import list_ontologies, get_ontology
 from prometheus_flask_exporter import PrometheusMetrics
+from flask_jwt_extended import jwt_required, JWTManager
 
 dictConfig({
     'version': 1,
@@ -31,6 +32,7 @@ dictConfig({
 })
 
 app = Flask(__name__)
+jwt = JWTManager(app)
 metrics = PrometheusMetrics(app)
 metrics.info('app_info', 'Application info', version='1.2.0')
 app.config['SWAGGER'] = {'openapi': '3.0.0', 'title': 'Swagger UI', 'uiversion': 3}
@@ -194,6 +196,7 @@ def get_concept_label():
 
 @app.route('/api/semantics/concept', methods=['POST'], endpoint='concepts_save')
 @swag_from('us-yml/post_concept.yml')
+@jwt_required()
 def save_concept():
     input_json = request.get_json()
     logging.debug('endpoint save concept, body=%s', input_json)
@@ -216,7 +219,8 @@ def save_concept():
 
 @app.route('/api/semantics/unit', methods=['POST'], endpoint='units_save')
 @swag_from('us-yml/post_unit.yml')
-def save_concept():
+@jwt_required()
+def save_unit():
     input_json = request.get_json()
     logging.debug('endpoint save unit, body=%s', input_json)
     try:
diff --git a/dbrepo-semantics-service/requirements.txt b/dbrepo-semantics-service/requirements.txt
index 403f546c43..bf2f5a864c 100644
--- a/dbrepo-semantics-service/requirements.txt
+++ b/dbrepo-semantics-service/requirements.txt
@@ -36,4 +36,5 @@ zope.event==4.6
 zope.interface==5.5.2
 html5lib==1.1
 pytest==7.2.1
-coverage==7.1.0
\ No newline at end of file
+coverage==7.1.0
+Flask-JWT-Extended==4.4.4
\ No newline at end of file
-- 
GitLab