Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support launching browser in WSL Ubuntu 18.04 #333

Merged
merged 7 commits into from
Mar 30, 2021
Merged

Conversation

jiasli
Copy link
Contributor

@jiasli jiasli commented Mar 29, 2021

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
Contributor Author

jiasli commented Mar 29, 2021

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.

msal/oauth2cli/authcode.py Outdated Show resolved Hide resolved
tests/test_authcode.py Outdated Show resolved Hide resolved
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