@@ -45,9 +45,10 @@ def is_wsl():
45
45
return platform_name == 'linux' and 'microsoft' in release
46
46
47
47
48
- def _browse (auth_uri ): # throws ImportError, possibly webbrowser.Error in future
48
+ def _browse (auth_uri , browser_name = None ): # throws ImportError, webbrowser.Error
49
+ """Browse uri with named browser. Default browser is customizable by $BROWSER"""
49
50
import webbrowser # Lazy import. Some distro may not have this.
50
- browser_opened = webbrowser .open (auth_uri ) # Use default browser. Customizable by $BROWSER
51
+ browser_opened = webbrowser .get ( browser_name ). open (auth_uri )
51
52
52
53
# In WSL which doesn't have www-browser, try launching browser with PowerShell
53
54
if not browser_opened and is_wsl ():
@@ -147,6 +148,7 @@ def get_port(self):
147
148
def get_auth_response (self , auth_uri = None , timeout = None , state = None ,
148
149
welcome_template = None , success_template = None , error_template = None ,
149
150
auth_uri_callback = None ,
151
+ browser_name = None ,
150
152
):
151
153
"""Wait and return the auth response. Raise RuntimeError when timeout.
152
154
@@ -173,6 +175,12 @@ def get_auth_response(self, auth_uri=None, timeout=None, state=None,
173
175
A function with the shape of lambda auth_uri: ...
174
176
When a browser was unable to be launch, this function will be called,
175
177
so that the app could tell user to manually visit the auth_uri.
178
+ :param str browser_name:
179
+ If you did
180
+ ``webbrowser.register("xyz", None, BackgroundBrowser("/path/to/browser"))``
181
+ beforehand, you can pass in the name "xyz" to use that browser.
182
+ The default value ``None`` means using default browser,
183
+ which is customizable by env var $BROWSER.
176
184
:return:
177
185
The auth response of the first leg of Auth Code flow,
178
186
typically {"code": "...", "state": "..."} or {"error": "...", ...}
@@ -190,7 +198,7 @@ def get_auth_response(self, auth_uri=None, timeout=None, state=None,
190
198
logger .info ("Open a browser on this device to visit: %s" % _uri )
191
199
browser_opened = False
192
200
try :
193
- browser_opened = _browse (_uri )
201
+ browser_opened = _browse (_uri , browser_name = browser_name )
194
202
except : # Had to use broad except, because the potential
195
203
# webbrowser.Error is purposely undefined outside of _browse().
196
204
# Absorb and proceed. Because browser could be manually run elsewhere.
0 commit comments