(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
@@ -258,8 +258,11 @@ async def mail_auth_callback(
# For failed authorization: # For failed authorization:
return await render_template( return await render_template(
"/message/mail/oauth/oauth_failure_v2.html", "/message/mail/oauth/oauth_failure_v2.html",
mail_client = mail_client.title(), mail_client = mail_client,
failure_hint = f"Unknown error. Please use log-id '{kwargs.get('log_id')}' to check with the support team." failure_hint = (
f"{client_response.message} "
f"Please use log-id '{kwargs.get('log_id')}' to check with the support team.".strip()
)
) )
+1 -1
View File
@@ -135,7 +135,7 @@ class MailController(CoreMessageController, ABC):
# Prepare the combined base filter: # Prepare the combined base filter:
sms_filter = {} sms_filter = {}
for k, v in (base_filter or {}).items(): sms_filter[k] = v 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: # Invoke the parent's constructor:
CoreMessageController.__init__( CoreMessageController.__init__(
+12 -12
View File
@@ -135,7 +135,7 @@ class GmailController(MailController):
cache = cache, cache = cache,
alert_url = alert_url, alert_url = alert_url,
http_client = http_client, http_client = http_client,
base_filter = {"client": "nimbusSmsIndia"}, base_filter = {"client": "gmail"},
debug = debug, debug = debug,
debug_prefix = debug_prefix, debug_prefix = debug_prefix,
debug_only_errors = debug_only_errors debug_only_errors = debug_only_errors
@@ -236,6 +236,16 @@ class GmailController(MailController):
response.action = "authorized" response.action = "authorized"
response.message = "The user has given authorization." 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 # 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 # 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: # achieved by 'request.url' like this:
@@ -259,17 +269,7 @@ class GmailController(MailController):
response.message = "Failed to get the user's profile from Gmail." response.message = "Failed to get the user's profile from Gmail."
return response return response
# Now we check if the email that the user originally claimed to authorize is the same as the one that gave the # We confirm if the expected email account and the one that gave authorization are the same:
# 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:
if auth_token.clientUserId["email"] != str(google_tokens.email): if auth_token.clientUserId["email"] != str(google_tokens.email):
response.message = ( response.message = (
f"We were expecting authorization from '{auth_token.clientUserId['email']}', " f"We were expecting authorization from '{auth_token.clientUserId['email']}', "