(20241202) Testing out the modified auth process.

This commit is contained in:
2024-12-02 18:47:38 +05:30
parent aed746190d
commit bcbad8ecdb
10 changed files with 419 additions and 173 deletions
+32 -7
View File
@@ -164,19 +164,35 @@ async def mail_callback(
if tokens:
# Add information and:
# Get the e-mail id that granted authorization:
user_profile = await current_app.gmail_client.get_user_profile(tokens = tokens)
tokens.email = user_profile.data["emailAddress"] if user_profile.success else None
# The e-mail id that we requested access to and the one that granted us access should be the same:
placeholder_token = await current_app.mail_oauth_model.set_token(
mongo_conn = current_app.data_mongo,
account_identifier = inbound_data["state"]
)
if (
(not placeholder_token) or
placeholder_token["clientUserId"] != str(tokens.email)
): return await render_template(
"/mail/oauth/oauth_failure_v2.html",
mail_client = mail_client.title(),
failure_hint = f"We were expecting authorization from '{placeholder_token['clientUserId']}' but got authorization from '{tokens.email}' instead."
)
# Save the tokens to the database
tokens_saved = await current_app.mail_oauth_model.set_token(
db_conn = current_app.sql_writer,
mongo_conn = current_app.data_mongo,
session_token = inbound_headers.get("X-Session-Token"),
user_identifier = inbound_data["state"],
account_identifier = inbound_data["state"],
token = tokens.model_dump()
)
# tokens_saved = False
# ┳┓
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
# ┛┗┗ ┛┣┛┗┛┛┗┛┗
@@ -192,11 +208,20 @@ async def mail_callback(
# }
# )
# Return an HTML response:
return await render_template(
"/mail/oauth/oauth_success_v2.html" if tokens_saved else "/mail/oauth/oauth_failure_v2.html",
mail_client = mail_client.title()
)
# Return an HTML response for success:
if tokens_saved:
return await render_template(
"/mail/oauth/oauth_success_v2.html",
mail_client = mail_client.title()
)
# Return an HTML response for failure:
else:
return await render_template(
"/mail/oauth/oauth_failure_v2.html",
mail_client = mail_client.title(),
failure_hint = f"Unknown error. Please use log-id '{kwargs['logId']}' to check with the support team."
)
# *****************************************************************************************************************