Skip to content

Commit 7e322d3

Browse files
committed
Prefer Edge when running on Linux, by using BROWSER env var
1 parent c687d5b commit 7e322d3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

msal/application.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
import warnings
1111
from threading import Lock
12+
import os
1213

1314
import requests
1415

@@ -27,6 +28,22 @@
2728

2829
logger = logging.getLogger(__name__)
2930

31+
if True: # Prefer launching Edge when running on Linux to support device-based CA.
32+
# This section only works when being run before webbrowser.open().
33+
# We could theoretically put it inside acquire_token_interactive(),
34+
# but that won't work for some of our major downstream applications
35+
# because they happen to invoke webbrowser.open() before calling MSAL.
36+
# So, we choose to add this logic at MSAL's module level.
37+
if ("BROWSER" not in os.environ # Customize it when end user has no preference
38+
and sys.platform == "linux"): # On Linux, only Edge will have CA support
39+
os.environ["BROWSER"] = ( # This is the executable file name
40+
# Hard-coding a well-known location can avoid unwittingly invoking
41+
# a potentially malicious "microsoft-edge" in current working directory.
42+
"/usr/bin/microsoft-edge")
43+
# Unavailable browser will be silently ignored and fall back to the default
44+
# More details at https://docs.python.org/3/library/webbrowser.html
45+
logger.debug("Prefer %s as browser for sign-in.", os.environ.get("BROWSER"))
46+
3047

3148
def extract_certs(public_cert_content):
3249
# Parses raw public certificate file contents and returns a list of strings

0 commit comments

Comments
 (0)