(20250116) Fixed auth-token bug for mail controllers.

This commit is contained in:
2025-01-16 17:08:15 +05:30
parent a5f88f1ff4
commit c78ab00ca7
3 changed files with 18 additions and 15 deletions
+1 -1
View File
@@ -135,7 +135,7 @@ class MailController(CoreMessageController, ABC):
# Prepare the combined base filter:
sms_filter = {}
for k, v in (base_filter or {}).items(): sms_filter[k] = v
sms_filter["serviceType"] = "sms"
sms_filter["serviceType"] = "email"
# Invoke the parent's constructor:
CoreMessageController.__init__(
+12 -12
View File
@@ -135,7 +135,7 @@ class GmailController(MailController):
cache = cache,
alert_url = alert_url,
http_client = http_client,
base_filter = {"client": "nimbusSmsIndia"},
base_filter = {"client": "gmail"},
debug = debug,
debug_prefix = debug_prefix,
debug_only_errors = debug_only_errors
@@ -236,6 +236,16 @@ class GmailController(MailController):
response.action = "authorized"
response.message = "The user has given authorization."
pass
# We fetch the auth-token associated with this authorization loop:
auth_token = await self.get_token_from_key(
mongo_data_conn = mongo_data_conn,
token_key = inbound_data["state"]
)
if not auth_token:
response.message = "Failed to load the auth-token for this flow."
return response
# Generate the tokens from the callback. Google sends all the needed params in the callback as the URL's query
# params. We can simply use the exact URL that was hit to generate the tokens. In Quart (and Flask) this can be
# achieved by 'request.url' like this:
@@ -259,17 +269,7 @@ class GmailController(MailController):
response.message = "Failed to get the user's profile from Gmail."
return response
# Now we check if the email that the user originally claimed to authorize is the same as the one that gave the
# authorization. We must fetch the auth-token for that:
auth_token = await self.get_token_from_key(
mongo_data_conn = mongo_data_conn,
token_key = inbound_data["state"]
)
if not auth_token:
response.message = "Failed to load the auth-token for this flow."
return response
# If the two email ids don't match:
# We confirm if the expected email account and the one that gave authorization are the same:
if auth_token.clientUserId["email"] != str(google_tokens.email):
response.message = (
f"We were expecting authorization from '{auth_token.clientUserId['email']}', "