From f5bf630c9f5c1e660d7f10666dfb600a96c5338b Mon Sep 17 00:00:00 2001 From: 1unarzDev Date: Fri, 24 Jul 2026 13:40:40 -0500 Subject: [PATCH] fix(imap): oauth2 url generation fix for microsoft outlook entra id --- config/oauth_script.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/config/oauth_script.py b/config/oauth_script.py index 325451d7..ef495908 100755 --- a/config/oauth_script.py +++ b/config/oauth_script.py @@ -57,8 +57,8 @@ "token_endpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/token", "revoke_endpoint": None, # Microsoft does not support token revocation via endpoint "scopes": [ - "https://outlook.office365.com/IMAP.AccessAsUser.All", - "https://outlook.office365.com/SMTP.Send", + "https://outlook.office.com/IMAP.AccessAsUser.All", + "https://outlook.office.com/SMTP.Send", "offline_access", ], "extra_auth_params": { @@ -171,8 +171,14 @@ def exchange_code(code, client_id, client_secret, provider): req = urllib.request.Request(cfg["token_endpoint"], data=data, method="POST") req.add_header("Content-Type", "application/x-www-form-urlencoded") - with urllib.request.urlopen(req) as resp: - return json.loads(resp.read().decode()) + try: + with urllib.request.urlopen(req) as resp: + return json.loads(resp.read().decode()) + except urllib.error.HTTPError as e: + body = e.read().decode() + print(f"Token exchange failed (HTTP {e.code}):", file=sys.stderr) + print(body, file=sys.stderr) + sys.exit(1) def refresh_access_token(refresh_token, client_id, client_secret, provider):