[Feature Request] Option to launch interactive auth on a different browser #750
-
MSAL client typePublic Problem StatementI currently use the delegated auth flow approach by using However, due to my institution's configuration, the authentication flow gets stuck indefinitely on the "Set up your device to get access" page. If I change my default browser to Chrome, it works successfully. I noticed setting the preferred browser using the environment variable is possible. However, it is only applicable to Linux. Proposed solutionIs it possible to specify a different browser programmatically without changing the default browser on my Mac? One way is to remove the Linux platform check to allow other platforms to specify different browser via environment variable, too. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
I haven't tried it on Mac, but the Python documentation hints that Python will honor the |
Beta Was this translation helpful? Give feedback.
-
With my default browser set to Brave on my Mac, this is what I tried: os.environ['BROWSER'] = 'chrome' # Opens Brave
os.environ['BROWSER'] = 'google-chrome' # Opens Brave
os.environ['BROWSER'] = 'chromium' # Opens Brave
os.environ['BROWSER'] = 'chromium-browser' # Opens Brave
os.environ['BROWSER'] = 'firefox' # Opens Firefox, but my institution doesn't support this browser Somehow, webbrowser has difficulty differentiating a chromium browser like Brave from Chrome (vice versa). Regarding that rabbit hole, I'm a little hesitated because I believe it will change the default browser permanently, unless I rerun it to change it back. |
Beta Was this translation helpful? Give feedback.
-
Quoted from the doc, "If the environment variable BROWSER exists, it is interpreted as the os.pathsep-separated list of browsers to try ahead of the platform defaults. When the value of a list part contains the string Can you try BROWSER="/path/to/your/chrome/executable %s"? |
Beta Was this translation helpful? Give feedback.
-
I think I got it! The path is a little convoluted, but I was able to launch it with Chrome now! # default browser on Mac = Brave
os.environ['BROWSER'] = "/Applications/Google\\ Chrome.app %s" # Opens Brave
os.environ['BROWSER'] = 'open -a /Applications/Google\\ Chrome.app %s' # Opens Chrome [UPDATED 2024-09-23]
app = msal.PublicClientApplication(CLIENT_ID, authority=AUTHORITY) Thank you very much for your help, @rayluo! I will close this ticket. |
Beta Was this translation helpful? Give feedback.
-
@rayluo slight tweak to the answer to prevent Python from complaining about "invalid escape sequence '\ '" # better!
os.environ['BROWSER'] = '/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome %s' # Opens Chrome Also, I noticed an oddity with this solution that I want to call out. Scenario 1: Chrome isn't Opened => Not WorkingIf Chrome isn't opened, I see the following in the log before Chrome is launched:
However, after completing my 2FA authentication, it is always stuck on this screen. Scenario 2: Open Chrome First => WorkingIf I open Chrome first and leave it opened before I run the script, I see this in my log:
This time, the auth flow works as expected and I can retrieve the access token from the response. Any idea what might cause Scenario 1's problem? Thank you. |
Beta Was this translation helpful? Give feedback.
-
@rayluo I think I solved it. You are right the TensorFlow message comes from the Chrome browser. # PARTIALLY WORKING SOLUTION ON MAC
# Works ONLY IF the Chrome browser is already opened.
# Hangs when going through the OAuth flow if MSAL opens the Chrome browser using webbrowser
os.environ['BROWSER'] = '/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome %s'
# FULLY WORKING SOLUTION ON MAC
# Works on existing the Chrome browser.
# Also works if MSAL opens the Chrome browser using webbrowser.
os.environ['BROWSER'] = 'open -a /Applications/Google\\ Chrome.app %s' I will update the answer above. This is much better than the rest of the workarounds I tried. :) |
Beta Was this translation helpful? Give feedback.
I think I got it! The path is a little convoluted, but I was able to launch it with Chrome now!
Thank you very much for your help, @rayluo! I will close this ticket.