Resetting utils subtree.
This commit is contained in:
@@ -181,6 +181,7 @@ async def request_oauth_authorization_url(
|
||||
session_token = inbound_headers["X-Session-Token"],
|
||||
user_info = kwargs["session_info"],
|
||||
client_user_id = {"email": inbound_data.mailId},
|
||||
auth = None,
|
||||
service_client = inbound_data.mailClient,
|
||||
auth_type = "oauth",
|
||||
sync_freq = inbound_data.syncFreq
|
||||
|
||||
+46
-39
@@ -112,7 +112,7 @@ def init(blueprint_setup_state):
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@sms_auth_bp.route("/auth", methods = ["GET"])
|
||||
@sms_auth_bp.route("/auth", methods = ["POST"])
|
||||
@set_api_version(api_version = "1.0.0")
|
||||
@read_input(sanitize_headers = False, sanitize_data = False)
|
||||
@get_session_info(key = "X-Session-Token", session_coro = "get_session")
|
||||
@@ -129,7 +129,7 @@ def init(blueprint_setup_state):
|
||||
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
|
||||
@validate_input(
|
||||
header_validator = lambda x: SMSAuthRequestHeaders(**x).model_dump(),
|
||||
data_validator = lambda x: SMSAuthRequestData(**{"client": x})
|
||||
data_validator = lambda x: SMSAuthRequestData(**x)
|
||||
)
|
||||
@handle_cancelled_request()
|
||||
async def request_oauth_authorization_url(
|
||||
@@ -161,45 +161,52 @@ async def request_oauth_authorization_url(
|
||||
)
|
||||
|
||||
# Start by assuming failure:
|
||||
auth_success = None
|
||||
token_id = None
|
||||
|
||||
# ┳ ┓ •┏ ┳┳
|
||||
# ┃┏┫┏┓┏┓╋┓╋┓┏ ┃┃┏┏┓┏┓
|
||||
# ┻┗┻┗ ┛┗┗┗┛┗┫ ┗┛┛┗ ┛
|
||||
# ┛
|
||||
# ┏┓ ┳┓• ┓ ┏┓┳┳┓┏┓ ┳ ┓•
|
||||
# ┣ ┏┓┏┓ ┃┃┓┏┳┓┣┓┓┏┏ ┗┓┃┃┃┗┓ ┃┏┓┏┫┓┏┓
|
||||
# ┻ ┗┛┛ ┛┗┗┛┗┗┗┛┗┻┛ ┗┛┛ ┗┗┛ ┻┛┗┗┻┗┗┻
|
||||
|
||||
# Make a user identifier from the session info:
|
||||
user_identifier = await current_app.mail_oauth_model.get_account_identifier(
|
||||
db_conn = current_app.sql_writer,
|
||||
mongo_conn = current_app.data_mongo,
|
||||
session_token = inbound_headers["X-Session-Token"],
|
||||
user_info = kwargs["session_info"],
|
||||
email_id = inbound_data.mailId,
|
||||
service_client = inbound_data.mailClient,
|
||||
auth_type = "oauth"
|
||||
)
|
||||
if user_identifier is None:
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.INTERNAL_SERVER_ERROR,
|
||||
message = "failed to generate user identifier"
|
||||
if inbound_data.messageClient == "nimbusSmsIndia":
|
||||
|
||||
token_id = await current_app.sms_auth_model.set(
|
||||
db_conn = current_app.sql_writer,
|
||||
mongo_conn = current_app.data_mongo,
|
||||
user_info = kwargs["session_info"],
|
||||
client_user_id = {
|
||||
"userId": inbound_data.auth.userId,
|
||||
"senderId": inbound_data.auth.senderId,
|
||||
"entityId": inbound_data.auth.enttiyId
|
||||
},
|
||||
auth = inbound_data.auth.model_dump(),
|
||||
token = None,
|
||||
service_client = inbound_data.messageClient,
|
||||
auth_type = "auth",
|
||||
sync_freq = 300,
|
||||
session_token = inbound_headers["X-Session-Token"]
|
||||
)
|
||||
user_identifier = str(user_identifier)
|
||||
|
||||
# ┏┓ ┏┓┳┳┓ •┓
|
||||
# ┣ ┏┓┏┓ ┃┓┃┃┃┏┓┓┃
|
||||
# ┻ ┗┛┛ ┗┛┛ ┗┗┻┗┗
|
||||
# ┏┓ ┏┓ ┳┓ ┓┓ ┏┓┳┳┓┏┓ ┓┏┓
|
||||
# ┣ ┏┓┏┓ ┗┓┏┓┓┏┓┏┓┏ ┣┫┓┏┃┃┏ ┗┓┃┃┃┗┓ ┃┫ ┏┓┏┓┓┏┏┓
|
||||
# ┻ ┗┛┛ ┗┛┗┻┗┛┗┛┗┫ ┻┛┗┻┗┛┗ ┗┛┛ ┗┗┛ ┛┗┛┗ ┛┗┗┫┗┻
|
||||
# ┛ ┛
|
||||
|
||||
if inbound_data.mailClient == "gmail":
|
||||
if inbound_data.messageClient == "savvyBulkSmsKenya":
|
||||
|
||||
# Get the authorization URL:
|
||||
auth_url = await current_app.gmail_client.get_authorization_url(
|
||||
scopes = SCOPES_GMAIL_MAIL_MANAGEMENT,
|
||||
state = user_identifier,
|
||||
access_type = "offline",
|
||||
approval_prompt = "force",
|
||||
include_granted_scopes = "true",
|
||||
user_email = inbound_data.mailId
|
||||
token_id = await current_app.sms_auth_model.set(
|
||||
db_conn = current_app.sql_writer,
|
||||
mongo_conn = current_app.data_mongo,
|
||||
user_info = kwargs["session_info"],
|
||||
client_user_id = {
|
||||
"partnerId": inbound_data.auth.partnerId,
|
||||
"shortCode": inbound_data.auth.shortCode
|
||||
},
|
||||
auth = inbound_data.auth.model_dump(),
|
||||
token = None,
|
||||
service_client = inbound_data.messageClient,
|
||||
auth_type = "auth",
|
||||
sync_freq = 300,
|
||||
session_token = inbound_headers["X-Session-Token"]
|
||||
)
|
||||
|
||||
# ┳┓
|
||||
@@ -209,11 +216,11 @@ async def request_oauth_authorization_url(
|
||||
|
||||
# Done here:
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.OK if auth_url else StatusCodes.FAILED,
|
||||
http_code = HttpCodes.SUCCESS if auth_url else HttpCodes.INTERNAL_SERVER_ERROR,
|
||||
status_code = StatusCodes.OK if token_id else StatusCodes.FAILED,
|
||||
http_code = HttpCodes.SUCCESS if token_id else HttpCodes.INTERNAL_SERVER_ERROR,
|
||||
data = {
|
||||
"mailClient": inbound_data.mailClient,
|
||||
"authorizationUrl": auth_url
|
||||
"messageClient": inbound_data.messageClient,
|
||||
"authorized": True
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user