(20241223) Zerodha auth now returns views.

This commit is contained in:
2024-12-23 16:27:52 +05:30
parent 3296fec639
commit 58e91fb15f
16 changed files with 112 additions and 294 deletions
@@ -57,7 +57,8 @@ from utils_v2.api.async_quart import (
only_whitelisted_ips,
limit_rate,
validate_input,
handle_cancelled_request
handle_cancelled_request,
handle_failed_request
)
# GMail-related utils:
@@ -112,6 +113,22 @@ def init(blueprint_setup_state):
# ---------------------------------------------------------------------------------------------------------------------
async def handle_auth_exception():
print("Hi! Cleaning up...")
return await render_template(
"/finstitutions/trading/oauth/oauth_failure_v2.html",
client = g.client_label,
failure_hint = (
f"Something went wrong (E). "
f"Please use log-id <b>'{g.log_id}'</b> to check with the support team."
)
)
# ---------------------------------------------------------------------------------------------------------------------
@trading_oauth_callback_bp.route("/callback/<trading_client>", methods = ["POST", "GET"])
@set_api_version(api_version = "1.0.0")
@read_input(sanitize_headers = False, sanitize_data = False)
@@ -127,6 +144,7 @@ def init(blueprint_setup_state):
@log_chain_to_mongo(attr_name = "logs_mongo")
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
@handle_cancelled_request()
@handle_failed_request(cleanup_coro = handle_auth_exception)
async def trading_oauth_callback(
trading_client: str = None,
inbound_headers: dict = None,
@@ -145,6 +163,13 @@ async def trading_oauth_callback(
:param kwargs: Any number of extra inputs supplied by the decorators.
:return: A standard response structure.
"""
# ┓┏ ┓┓ ┓┏ • ┓ ┓
# ┣┫┏┓┏┓┏┫┃┏┓ ┃┃┏┓┏┓┓┏┓┣┓┃┏┓┏
# ┛┗┗┻┛┗┗┻┗┗ ┗┛┗┻┛ ┗┗┻┗┛┗┗ ┛
# Store needed values in 'g':
g.log_id = kwargs.get("log_id")
g.client_label = "Zerodha (Kite)"
# Start by assuming failure:
success = None
@@ -165,17 +190,43 @@ async def trading_oauth_callback(
# ┛┗┗ ┛┣┛┗┛┛┗┛┗
# ┛
# # No valid client:
# if success is None: return ResponseModel(
# status_code = StatusCodes.FAILED,
# http_code = HttpCodes.BAD_REQUEST,
# message = f"Invalid/unimplemented client '{trading_client}'."
# )
#
# # When the client was valid:
# return ResponseModel(
# status_code = StatusCodes.OK if success else StatusCodes.FAILED,
# http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
# )
# No valid client:
if success is None: return ResponseModel(
status_code = StatusCodes.FAILED,
http_code = HttpCodes.BAD_REQUEST,
message = f"Invalid/unimplemented client '{trading_client}'."
if success is None: return await render_template(
"/finstitutions/trading/oauth/oauth_failure_v2.html",
client = g.client_label,
failure_hint = (
f"Invalid client '{g.client_label}' selected. "
f"Please use log-id '{g.log_id}' to check with the support team."
)
)
# When the client was valid:
return ResponseModel(
status_code = StatusCodes.OK if success else StatusCodes.FAILED,
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
# Successful auth:
if success: return await render_template(
"/finstitutions/trading/oauth/oauth_success_v2.html",
client = g.client_label
)
# Failed auth:
if success is None: return await render_template(
"/finstitutions/trading/oauth/oauth_failure_v2.html",
client = g.client_label,
failure_hint = (
f"Something went wrong (NE). "
f"Please use log-id '{g.log_id}' to check with the support team."
)
)