Skip to content

Support launching browser in WSL Ubuntu 18.04 - #333

Merged
Ray Luo (rayluo) merged 7 commits into
AzureAD:devfrom
jiasli:wsl
Mar 30, 2021
Merged

Ray Luo (rayluo) merged 7 commits into
AzureAD:devfrom
jiasli:wsl

Conversation

@jiasli

Copy link
Copy Markdown
Contributor

Fix #332

The code is migrated from Azure CLI:

https://github.com/Azure/azure-cli/blob/3bff786b9e337aa35bb4cc64a09e5600a35663f8/src/azure-cli-core/azure/cli/core/util.py#L642-L648

    if is_wsl():   # windows 10 linux subsystem
        try:
            # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe
            # Ampersand (&) should be quoted
            return subprocess.call(['powershell.exe', '-Command', 'Start-Process "{}"'.format(url)])
        except OSError:  # WSL might be too old  # FileNotFoundError introduced in Python 3
            pass

_browse now tries webbrowser.open first. If that fails and WSL is detected, launch browser with powershell.exe.

As for why powershell.exe is preferred over cmd.exe, it is discussed in Azure/azure-cli#12851.

@jiasli

Copy link
Copy Markdown
Contributor Author

www-browser internally also uses powershell.exe

https://github.com/wslutilities/wslu/blob/221e85457c01e92db675cc7b24a49dfcdfacc6a9/src/wslu-header#L156

	"$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NonInteractiveExecutionPolicy Bypass -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::GetEncoding($cp); $@"

But we can keep it simple.

Comment thread msal/oauth2cli/authcode.py
Comment thread msal/oauth2cli/authcode.py Outdated
Comment thread tests/test_authcode.py Outdated
Jiashuo Li and others added 2 commits March 30, 2021 20:22
Co-authored-by: Ray Luo <rayluo.mba@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support auth code flow in WSL Ubuntu 18.04

2 participants