From f15a638251006fa08fbb2b460303e0aeb0eb443e Mon Sep 17 00:00:00 2001 From: khushal Date: Wed, 4 Dec 2024 13:08:40 +0530 Subject: [PATCH] (20241204) Mail OAuth URL modified. --- api/blueprints/mail/oauth_callback.py | 5 ++++- api/blueprints/mail/oauth_request.py | 2 +- models/behaviour/mail/oauth_v2.py | 23 ++++++++++++++--------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/api/blueprints/mail/oauth_callback.py b/api/blueprints/mail/oauth_callback.py index b840f32..a97afda 100644 --- a/api/blueprints/mail/oauth_callback.py +++ b/api/blueprints/mail/oauth_callback.py @@ -136,7 +136,10 @@ async def handle_gmail_callback() -> render_template: # to us when the authorization was initiated. We don't mind any e-mail id being used, but we need them to be the # same at both ends: user_profile = await current_app.gmail_client.get_user_profile(tokens = tokens) - tokens.email = user_profile.data["emailAddress"] if user_profile.success else None + if user_profile.success: + tokens.email = user_profile.data["emailAddress"] + tokens.displayName = user_profile.data["displayName"] + tokens.displayPictureUrl = user_profile.data["displayPictureUrl"] # Here's where we do the checking of the e-mails, # if they don't match, we reject the authorization: diff --git a/api/blueprints/mail/oauth_request.py b/api/blueprints/mail/oauth_request.py index 59854a8..f4d8658 100644 --- a/api/blueprints/mail/oauth_request.py +++ b/api/blueprints/mail/oauth_request.py @@ -115,7 +115,7 @@ def init(blueprint_setup_state): # --------------------------------------------------------------------------------------------------------------------- -@mail_oauth_bp.route("/auth/oauth/url/request", methods = ["GET"]) +@mail_oauth_bp.route("/oauth", methods = ["GET"]) @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") diff --git a/models/behaviour/mail/oauth_v2.py b/models/behaviour/mail/oauth_v2.py index 51b3466..c8a2e6d 100644 --- a/models/behaviour/mail/oauth_v2.py +++ b/models/behaviour/mail/oauth_v2.py @@ -237,19 +237,24 @@ class MailOAuthModel(BaseModel): # Tell MariaDB that the token was saved: if mongo_json is not None: + token_notes = { + "email": token["email"], + "displayName": token["displayName"], + "displayPictureUrl": token["displayPictureUrl"], + } db_json = await self.call_procedure( db_conn = db_conn, proc_name = "entity_integration_save", proc_args = ( - mongo_json["user"]["entityId"], # ............................................. 'p_entity_id' - mongo_json["client"], # ....................................................... 'p_provider' - "Auth Granted", # ............................................................. 'p_current_status' - "Set Token", # ................................................................ 'p_last_action' - None, # ....................................................................... 'p_display_name' - None, # ....................................................................... 'p_display_picture' - account_identifier, # ......................................................... 'p_token_id' - json.to_string(python_data = {"email": token["email"]}, no_space = True), # ... 'p_notes' - mongo_json["user"]["userId"] # ................................................ 'p_created_by' + mongo_json["user"]["entityId"], # ............................... 'p_entity_id' + mongo_json["client"], # ......................................... 'p_provider' + "Auth Granted", # ............................................... 'p_current_status' + "Set Token", # .................................................. 'p_last_action' + token["displayName"], # ......................................... 'p_display_name' + token["displayPictureUrl"], # ................................... 'p_display_picture' + account_identifier, # ........................................... 'p_token_id' + json.to_string(python_data = token_notes, no_space = True), # ... 'p_notes' + mongo_json["user"]["userId"] # .................................. 'p_created_by' ), session_token = session_token )