httpx_auth
httpx_auth copied to clipboard
Document workaround to run a text-mode browser in a subprocess
I figured this out to support an OAuth flow within a Dockerized environment, but it might also be helpful for other authentication backends.
According to the webbrowser module documentation:
For non-Unix platforms, or when a remote browser is available on Unix, the controlling process will not wait for the user to finish with the browser, but allow the remote browser to maintain its own windows on the display. If remote browsers are not available on Unix, the controlling process will launch a new browser and wait.
When you are running a project in a containerized environment, you probably don't have access to a graphical interface. In that case, webbrowser.open() blocks and waits for the text-mode browser to close. However, the opened browser attempts to load the content provided by httpx-auth's authentication response server. This becomes a deadlock - the browser is loading content from the auth response server, but the auth response server cannot send the content because it is blocking on the webbrowser.
The webbrowser module already has support for opening a text-mode browser in a non-blocking fashion:
if '%s' in browser:
# User gave us a command line, split it into name and args
browser = shlex.split(browser)
if browser[-1] == '&':
return BackgroundBrowser(browser[:-1])
else:
return GenericBrowser(browser)
This PR simply documents how to correctly trigger the preexisting functionality to open a text-mode browser in a separate process.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
Since this is just a documentation update, I suspect that the test failures are unrelated, or need to be rerun.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
Tests now pass. @Colin-b Can I get a review and merge? TIA! 😄
thx a lot !