(20250625) - Implemented the ecommerce shopify auth integration.

with multiple files added new API for get token details
This commit is contained in:
yatmesh
2025-06-25 14:06:02 +05:30
parent 388b9bdd1b
commit c022844824
14 changed files with 1029 additions and 7 deletions
+193
View File
@@ -0,0 +1,193 @@
"""
AUTHOR:
Omkar Khandare
DATE:
Wednesday, 25rd June., 2025.
OBJECTIVE:
To disable chat accounts.
REFERENCES:
N/A
DOWNLOADS:
N/A
NOTES:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
from api.blueprints.common.disable import auth_token_disable_bp
sys.path.append(".")
sys.path.append("..")
# For using Quart:
from quart import Blueprint, current_app, request
# My utils:
from utils_v2.string import json
from utils_v2.api.codes import StatusCodes, HttpCodes
from utils_v2.api.response import ResponseModel
from utils_v2.api.async_quart import (
set_api_version,
read_input,
get_session_info,
log_request_to_mongo,
log_chain_to_mongo,
should_not_be_under_maintenance,
only_whitelisted_ips,
limit_rate,
validate_input,
handle_cancelled_request
)
# Common:
from shared import constants
# Data Models:
from models.core.user import CoreUserInfoModel
from models.api.common.integrations.auth_get import AuthTokenGetRequestData, AuthTokenGetRequestHeaders
# Helpers:
from api.helpers.user import token_check
# To work with MongoDB:
from bson import ObjectId
# For asynchronous activities:
import asyncio
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# Related to Quart:
integration_get_bp = Blueprint("integration get", __name__)
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
@integration_get_bp.record_once
def init(blueprint_setup_state):
# This gets called when the blueprint is registered.
# Consider this to be a one-time setup for the whole blueprint:
pass
# ---------------------------------------------------------------------------------------------------------------------
@integration_get_bp.route("/token", methods = ["GET", "POST"])
@set_api_version(api_version = "1.0.0")
@read_input(sanitize_headers = False, sanitize_data = False)
@log_request_to_mongo(
attr_name = "logs_mongo",
project = constants.PROJECT_NAME,
log_type = constants.MODULE_NAME,
operation = "integrationTokenGetAPI",
log_input = True,
log_output = True,
sensitive_keys = ["sessionToken", "X-Session-Token", "tokenKey"]
)
@log_chain_to_mongo(attr_name = "logs_mongo")
@only_whitelisted_ips(attr_name="whitelisted_ips")
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
@validate_input(
header_validator = None,
data_validator = lambda x: AuthTokenGetRequestData(**x)
)
@handle_cancelled_request()
async def get_integrations_token(
inbound_headers: dict = None,
inbound_data: dict | AuthTokenGetRequestData = None,
inbound_files: dict = None,
**kwargs
):
"""
Use this when a user wants to remove/disable his account.
:param inbound_headers: auto-extracted by the decorators.
:param inbound_data: auto-extracted by the decorators.
:param inbound_files: auto-extracted by the decorators.
:param kwargs: Any number of extra inputs supplied by the decorators.
:return: A standard response structure.
"""
print("INBOUND", inbound_data)
# ┳┳┓ ┓•┏ ┏┓
# ┃┃┃┏┓┏┫┓╋┓┏ ┗┓╋┏┓╋┓┏┏
# ┛ ┗┗┛┗┻┗┛┗┫ ┗┛┗┗┻┗┗┻┛
# ┛
# Update the message:
auth_token = await current_app.core_auth_token_controller.get_token_from_key(
mongo_data_conn=current_app.data_mongo,
token_key=inbound_data.tokenKey
)
print("AUTH TOKEN RES:", auth_token)
success = False if auth_token is None else True
# ┳┓
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
# ┛┗┗ ┛┣┛┗┛┛┗┛┗
# ┛
# Done here:
return ResponseModel(
status_code = StatusCodes.OK if success else StatusCodes.FAILED,
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
data = auth_token.to_json() if success else auth_token
)
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass
+25 -1
View File
@@ -236,6 +236,29 @@ async def authorize_software_client(
success = response.success
message = f"Action Chain '{response.actionChain}': {response.message}"
elif inbound_data.softwareClient == "shopify":
# Make the client controller test and save the auth:
response = await current_app.shopify_controller.save_auth(
sql_conn=current_app.sql_writer,
mongo_data_conn=current_app.data_mongo,
auth=inbound_data.auth,
user=kwargs.get("session_info"),
session_token=inbound_headers.get("X-Session-Token")
)
# Note down the results:
success = response.success
message = response.message
token_id = response.token_id
auth_url_success = ""
auth_url_failed = ""
if token_id is not None:
auth_url_success = f"https://api.thecaoffice.com/shopify/auth/template?status=1&token={token_id}&storeName={inbound_data.auth.storeName}&storeUrl={inbound_data.auth.storeUrl}"
else:
auth_url_failed = f"https://api.thecaoffice.com/shopify/auth/template?status=0&storeName={inbound_data.auth.storeName}&storeUrl={inbound_data.auth.storeUrl}"
# ┳┓
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
# ┛┗┗ ┛┣┛┗┛┛┗┛┗
@@ -248,7 +271,8 @@ async def authorize_software_client(
message = message,
data = {
"client": inbound_data.softwareClient,
"authorized": success
"authorized": success,
"authorizationUrl": auth_url_success if success else auth_url_failed
}
)
+14 -1
View File
@@ -102,6 +102,7 @@ from controllers_v2.finstitutions.payments.safaricom_mpesa_express import Safari
from controllers_v2.software.mikrotik.all_mikrotik import AllMikroTikController
from controllers_v2.software.mikrotik.mikrotik_pppoe_1000 import MikroTikPPPoE1000Controller
from controllers_v2.software.mikrotik.mikrotik_hostpot_1000 import MikroTikHotspot1000Controller
from controllers_v2.software.ecommerce.shopify import ShopifyAppController
# ---
from controllers_v2.common.otp.timed_otp import TimedOTPController
@@ -157,7 +158,7 @@ from api.blueprints.common.disable import auth_token_disable_bp
from api.blueprints.common.session_token import session_token_bp
from api.blueprints.common.otp.timed_otp import timed_otp_bp
from api.blueprints.common.otp.timed_otp_test import timed_otp_bp_test
from api.blueprints.common.integrations.get import integration_get_bp
# Tech and Testing Blueprints:
from api.blueprints.tech.chat_alerts import tech_chat_alert_bp
from api.blueprints.test.callback import test_callback_bp
@@ -233,6 +234,7 @@ app.register_blueprint(trading_symbols_list_bp, url_prefix = f"/{MODULE_BASE}/fi
app.register_blueprint(auth_token_disable_bp, url_prefix = f"/{MODULE_BASE}")
app.register_blueprint(session_token_bp, url_prefix = f"/{MODULE_BASE}")
app.register_blueprint(timed_otp_bp, url_prefix = f"/{MODULE_BASE}/otp/timed")
app.register_blueprint(integration_get_bp, url_prefix = f"/{MODULE_BASE}/integrations/")
# app.register_blueprint(timed_otp_bp_test, url_prefix = f"/{MODULE_BASE}/otp/timed")
# AI Blueprints:
@@ -601,6 +603,17 @@ async def app_startup(**kwargs):
)
current_app.printer("Software/MikroTik (C) ready.")
# software / ecommerce
current_app.shopify_controller = ShopifyAppController(
cache=current_app.module_cache,
http_client=current_app.http_client,
alert_url=current_app.script_data["alerts"]["url"],
debug=enable_debugging
)
current_app.printer("Software/ecommerce (C) ready.")
# Common / OTP:
current_app.timed_otp_controller = TimedOTPController(
debug = enable_debugging