diff --git a/backend/app.py b/backend/app.py index 97f6ffb..892b041 100644 --- a/backend/app.py +++ b/backend/app.py @@ -46,7 +46,7 @@ Migrate(app, db) db.init_app(app) -app.logger.setLevel(logging.INFO) +app.logger.setLevel(logging.DEBUG) app.register_blueprint(api_v1) app.register_blueprint(web) diff --git a/backend/areas/auth/auth.py b/backend/areas/auth/auth.py index c972752..11438d7 100644 --- a/backend/areas/auth/auth.py +++ b/backend/areas/auth/auth.py @@ -8,14 +8,12 @@ from areas.apps import App, AppRole from config import * from helpers import HydraOauth, BadRequest, KratosApi - @api_v1.route("/login", methods=["POST"]) @cross_origin() def login(): authorization_url = HydraOauth.authorize() return jsonify({"authorizationUrl": authorization_url}) - @api_v1.route("/hydra/callback") @cross_origin() def hydra_callback(): diff --git a/backend/areas/auth/lit_auth.py b/backend/areas/auth/lit_auth.py index f99432c..d0d4e96 100644 --- a/backend/areas/auth/lit_auth.py +++ b/backend/areas/auth/lit_auth.py @@ -1,14 +1,23 @@ from multiprocessing import current_process from flask import jsonify, request -from flask_jwt_extended import create_access_token +from flask_jwt_extended import create_access_token, jwt_required from flask_cors import cross_origin from datetime import timedelta +from helpers.authentik_api import AuthentikApi from areas import api_v1 from config import * from helpers import LITOauth, BadRequest +@api_v1.route("/logout", methods=["POST"]) +@cross_origin() +@jwt_required() +def logout(): + res = AuthentikApi.post("/flows/executor/default-invalidation-flow/") + print(res) + return jsonify({}) + @api_v1.route("/login", methods=["POST"]) @cross_origin() def login(): diff --git a/backend/helpers/authentik_api.py b/backend/helpers/authentik_api.py index e8e9a4d..7dacdea 100644 --- a/backend/helpers/authentik_api.py +++ b/backend/helpers/authentik_api.py @@ -32,11 +32,25 @@ class AuthentikApi: # TODO: check if can be replaced with apispec generated api raise AuthentikError() @staticmethod - def __paginate(res: requests.Response): # TODO: test this + def post(url, data=[]): + try: + res = requests.post(f"{AUTHENTIK_BASEURL}{url}", headers={ + "Authorization": f"Bearer {AuthentikApi.__token()}"}, data=data) + AuthentikApi.__handleError(res) + if ("pagination" in res.json()): + return AuthentikApi.__paginate(res) + return res.json() + except AuthentikError as err: + raise err + except: + raise AuthentikError() + + @staticmethod + def __paginate(res: requests.Response): # TODO: test this results = res.json()["results"] for page in range(1, res.json()["pagination"]["total_pages"]): res = requests.get( f"{res.request.url}", headers=res.request.headers, params={'page': page}) AuthentikApi.__handleError(res) results.append(res.json()["results"]) - return results \ No newline at end of file + return results