From 19870edf734ab7fababdb3ad1015cd74d1bd482d Mon Sep 17 00:00:00 2001 From: lennyaiko Date: Thu, 3 Apr 2025 16:54:14 +0100 Subject: [PATCH] progress on JWT --- .example.env | 1 + .gitignore | 3 +- .vscode/settings.json | 24 ++++++++++++++ app/api/routes/routes.py | 36 ++++++++++++--------- app/swagger/paths/Authorize.json | 54 ++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 15 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 app/swagger/paths/Authorize.json diff --git a/.example.env b/.example.env index 006be8c..0ba4d48 100644 --- a/.example.env +++ b/.example.env @@ -7,6 +7,7 @@ BASIC_AUTH_PASSWORD=****** SWAGGER_URL="/documentation" API_URL="/swagger.json" +JWT_SECRET_KEY=****** DATABASE_USER=***** diff --git a/.gitignore b/.gitignore index 20bea99..e4cafc3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ __pycache__/ app.log .DS_Store migrations/__pycache__/ -migrations/*.pycg \ No newline at end of file +migrations/*.pycg +./vscode \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b79483b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,24 @@ +{ + "editor.lineNumbers": "off", + "editor.padding.top": 3, + "editor.padding.bottom": 3, + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.fontSize": 14, + "editor.lineHeight": 4.5, + "editor.suggestFontSize": 15, + // "editor.suggestLineHeight": 4, + "breadcrumbs.enabled": false, + "workbench.tips.enabled": false, + "workbench.statusBar.visible": false, + // "workbench.editor.showTabs": "single", + "git.enableSmartCommit": true, + "workbench.editor.editorActionsLocation": "hidden", + // "workbench.activityBar.location": "hidden", + "workbench.editor.enablePreviewFromQuickOpen": false, + "editor.lightbulb.enabled": "off", + "editor.selectionHighlight": false, + "editor.overviewRulerBorder": false, + "editor.renderLineHighlight": "none", + "editor.occurrencesHighlight": "off" +} diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 8530b0e..4396dbc 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -6,10 +6,10 @@ from app.api.services import ( LoanStatusService, RepaymentService, CustomerConsentService, - NotificationCallbackService + NotificationCallbackService, ) from app.utils.logger import logger -from app.api.middlewares import enforce_json, require_auth +from app.api.middlewares import enforce_json, require_auth import os @@ -23,21 +23,20 @@ def cors_middleware(): # Swagger JSON file -@api.route("/swagger.json", methods=['GET']) +@api.route("/swagger.json", methods=["GET"]) def swagger_json(): swagger_dir = os.path.join("swagger") return send_from_directory(swagger_dir, "digifi_swagger.json") - -@api.route('/swagger/') +@api.route("/swagger/") def serve_paths(filename): swagger_dir = os.path.join("swagger") return send_from_directory(swagger_dir, filename) # EligibilityCheck Endpoint -@api.route('/EligibilityCheck', methods=['POST']) +@api.route("/EligibilityCheck", methods=["POST"]) @require_auth def eligibility_check(): data = request.get_json() @@ -45,8 +44,9 @@ def eligibility_check(): response = EligibilityCheckService.process_request(data) return response + # SelectOffer Endpoint -@api.route('/SelectOffer', methods=['POST']) +@api.route("/SelectOffer", methods=["POST"]) @require_auth def select_offer(): data = request.get_json() @@ -56,7 +56,7 @@ def select_offer(): # ProvideLoan Endpoint -@api.route('/ProvideLoan', methods=['POST']) +@api.route("/ProvideLoan", methods=["POST"]) @require_auth def provide_loan(): data = request.get_json() @@ -66,7 +66,7 @@ def provide_loan(): # LoanStatus Endpoint -@api.route('/LoanStatus', methods=['POST']) +@api.route("/LoanStatus", methods=["POST"]) @require_auth def loan_status(): data = request.get_json() @@ -76,7 +76,7 @@ def loan_status(): # Repayment Endpoint -@api.route('/Repayment', methods=['POST']) +@api.route("/Repayment", methods=["POST"]) @require_auth def repayment(): data = request.get_json() @@ -86,7 +86,7 @@ def repayment(): # CustomerConsent Endpoint -@api.route('/CustomerConsent', methods=['POST']) +@api.route("/CustomerConsent", methods=["POST"]) @require_auth def customer_consent(): data = request.get_json() @@ -96,7 +96,7 @@ def customer_consent(): # NotificationCallback Endpoint -@api.route('/NotificationCallback', methods=['POST']) +@api.route("/NotificationCallback", methods=["POST"]) @require_auth def notification_callback(): data = request.get_json() @@ -106,6 +106,14 @@ def notification_callback(): # Health Check Endpoint -@api.route('/health', methods=['GET']) +@api.route("/health", methods=["GET"]) def health_check(): - return {"status": "ok"} , 200 \ No newline at end of file + return {"status": "ok"}, 200 + + +# Authorize endpoint +@api.route("/Authorize", methods=["POST"]) +def authorize(): + data = request.get_json() + # logger.info(f"Authorize request received: {data}") + return jsonify(data) diff --git a/app/swagger/paths/Authorize.json b/app/swagger/paths/Authorize.json new file mode 100644 index 0000000..081e820 --- /dev/null +++ b/app/swagger/paths/Authorize.json @@ -0,0 +1,54 @@ +{ + "post": { + "tags": ["Authorize"], + "summary": "Customer Authorize Request", + "description": "Customer Authorize Request", + "operationId": "Authorize", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "../schemas/AuthorizeRequest.json" + } + }, + "application/xml": { + "schema": { + "$ref": "../schemas/AuthorizeRequest.json" + } + }, + "application/x-www-form-urlencoded": { + "schema": { + "$ref": "../schemas/AuthorizeRequest.json" + } + } + } + }, + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "../schemas/AuthorizeResponse.json" + } + }, + "application/xml": { + "schema": { + "$ref": "../schemas/AuthorizeResponse.json" + } + } + } + }, + "400": { + "description": "Invalid request parameters" + }, + "422": { + "description": "Validation exception" + }, + "500": { + "description": "Internal server error" + } + } + } +}