Skip to content

Support auth code flow in WSL Ubuntu 18.04 #332

Description

@jiasli

It will be good for MSAL to support auth code flow in WSL Ubuntu 18.04.

webbrowser doesn't work in WSL Ubuntu 18.04 due to the lack of www-browser:

$ python3 -V
Python 3.6.9
$ python3 -c "import webbrowser; print(webbrowser.open('https://microsoft.com'))"
False
$ python3 -c "import webbrowser; print(webbrowser.get())"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.6/webbrowser.py", line 51, in get
    raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser
$ which www-browser
$

WSL Ubuntu 20.04 already supports this:

$ python3 -V
Python 3.8.5
$ python3 -c "import webbrowser; print(webbrowser.get().name)"
www-browser
$ which www-browser
/usr/bin/www-browser

Azure CLI supports WSL Ubuntu 18.04 by

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

def open_page_in_browser(url):
    import subprocess
    import webbrowser
    platform_name, _ = _get_platform_info()


    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

Without this functionality, Azure CLI will have a regression when using MSAL.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions