(20241202) Testing out the modified auth process.
This commit is contained in:
@@ -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."
|
||||
)
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user