Skip to content

[Bug] enable_broker_on_wsl prints pring to stdout #854

Description

@galpin

Describe the bug
Using the PublicClientApplication.enable_broker_on_wsl argument, the line "{{\"ping\",\"success\"}}} is written to stdout.

To Reproduce

from msal import PublicClientApplication


client_id = "REDACTED"
authority = "REDACTED"
scopes = [f"api://{client_id}/.default"]

app = PublicClientApplication(
    client_id=client_id,
    authority=authority,
    enable_broker_on_windows=True,
    enable_broker_on_wsl=True,
)
token = app.acquire_token_interactive(
    scopes=scopes,
    parent_window_handle=PublicClientApplication.CONSOLE_WINDOW_HANDLE,
)

Expected behavior
Nothing should be output to stdout.

What you see instead

> uv run repro.py
"{{\"ping\",\"success\"}}}"

The MSAL Python version you are using
1.33.0

Activity

  1. rayluo commented on Sep 23, 2025

    @rayluo
    Contributor

    This is a known issue of the underlying PyMsalRuntime package. Assigning to fengga and CC Ashok Kumar Ramakrishnan (@ashok672) , Iulian C. (@iulico-1)

    Also tracked internally at https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3387107

  2. xinyuxu1026 commented on Oct 1, 2025

    @xinyuxu1026
    Contributor

    Acked. This is issue is addressed previously. Currently waiting for the next pymsalruntime release so that customer can adopt a new version which contains the fix.

  3. xinyuxu1026 commented on Oct 15, 2025

    @xinyuxu1026
    Contributor

    Hi Martin Galpin (@galpin) , the fix is in pymsalruntime 0.20.0 (released 10/13/2025), could you please upgrade to this version and see if this is fixed? Thanks.

  4. rayluo commented on Oct 15, 2025

    @rayluo
    Contributor

    Hi @galpin , the fix is in pymsalruntime 0.20.0 (released 10/13/2025), could you please upgrade to this version and see if this is fixed? Thanks.

    Note that the PyMsalRuntime 0.20.0 was released after the latest MSAL Python 1.34.0, so, a pip install msal does NOT currently pick up PyMsalRuntime 0.20.0 by default, until we ship the next version of MSAL in the future. Meanwhile, Martin Galpin (@galpin) you can manually do a pip install pymsalruntime==0.20.0 in your environment and see how that goes.

  5. galpin commented on Nov 3, 2025

    @galpin
    Author

    Hi Ray Luo (@rayluo),

    Sorry for the slow response.

    Unfortunately v0.20.0 results in a new error compared to 0.18.1, see below. Running in Ubuntu 22.04.5 LTS via WSL.

    Let me know if you need anything else.

    v0.18.1

    > uv run -p 3.12 --with msal==1.34.0 --with pymsalruntime==0.18.1 repro.py
    Using CPython 3.12.7
    Removed virtual environment at: .venv
    Creating virtual environment at: .venv
    Installed 20 packages in 32ms
    "{{\"ping\",\"success\"}}}"

    v0.20.0

    > uv run -p 3.12 --with msal==1.34.0 --with pymsalruntime==0.20.0 repro.py
    Installed 11 packages in 15ms
    Traceback (most recent call last):
      File "/home/galpin/r/rbauth/repro.py", line 7, in <module>
        app = PublicClientApplication(
              ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/galpin/.cache/uv/archive-v0/humv0xhXhsbo5KXE5fkxs/lib/python3.12/site-packages/msal/application.py", line 2046, in __init__
        super(PublicClientApplication, self).__init__(
      File "/home/galpin/.cache/uv/archive-v0/humv0xhXhsbo5KXE5fkxs/lib/python3.12/site-packages/msal/application.py", line 669, in __init__
        self._decide_broker(allow_broker, enable_pii_log)
      File "/home/galpin/.cache/uv/archive-v0/humv0xhXhsbo5KXE5fkxs/lib/python3.12/site-packages/msal/application.py", line 712, in _decide_broker
        _init_broker(enable_pii_log)
      File "/home/galpin/.cache/uv/archive-v0/humv0xhXhsbo5KXE5fkxs/lib/python3.12/site-packages/msal/application.py", line 31, in _init_broker
        from . import broker  # Trigger Broker's initialization, lazily
        ^^^^^^^^^^^^^^^^^^^^
      File "/home/galpin/.cache/uv/archive-v0/humv0xhXhsbo5KXE5fkxs/lib/python3.12/site-packages/msal/broker.py", line 14, in <module>
        import pymsalruntime  # Its API description is available in site-packages/pymsalruntime/PyMsalRuntime.pyi
        ^^^^^^^^^^^^^^^^^^^^
      File "/home/galpin/.cache/uv/archive-v0/humv0xhXhsbo5KXE5fkxs/lib/python3.12/site-packages/pymsalruntime/__init__.py", line 11, in <module>
        ctypes.CDLL(library_path)
      File "/home/galpin/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/ctypes/__init__.py", line 379, in __init__
        self._handle = _dlopen(self._name, mode)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
    OSError: libwebkit2gtk-4.1.so.0: cannot open shared object file: No such file or directory
    > 
  6. rayluo commented on Nov 4, 2025

    @rayluo
    Contributor

    Martin Galpin (@galpin) , thanks for the report, but please create a new github issue for it to be properly tracked. CC: xinyuxu1026

  7. xinyuxu1026 commented on Nov 4, 2025

    @xinyuxu1026
    Contributor

    Martin Galpin (@galpin) , pymsalruntime v0.20.0 does not come with libwebkitgtk bundled, the user needs to manually install it. Here is the documentation: https://learn.microsoft.com/en-us/entra/msal/python/advanced/linux-broker-py?tabs=ubuntudep#linux-dependencies

  8. galpin commented on Nov 4, 2025

    @galpin
    Author

    xinyuxu1026 Thanks - installing the package resolves the error. If the change of behaviour is expected (e.g. 0.18.1 did not require libwebkitgtk) then I'm happy to ignore.

  9. xinyuxu1026 commented on Nov 4, 2025

    @xinyuxu1026
    Contributor

    Martin Galpin (@galpin) , sounds great! This is expected

  10. rayluo commented on Nov 4, 2025

    @rayluo
    Contributor

    pymsalruntime v0.20.0 does not come with libwebkitgtk bundled, the user needs to manually install it. Here is the documentation: https://learn.microsoft.com/en-us/entra/msal/python/advanced/linux-broker-py?tabs=ubuntudep#linux-dependencies

    xinyuxu1026 , that doc might not be very discoverable. Could we at least add a try ... except ... in that code path and then emit an actionable message on the spot, such as "Extra dependency missing, please follow https://learn.microsoft.com/en-us/entra/msal/python/advanced/linux-broker-py?tabs=ubuntudep#linux-dependencies".

    Also, let's ping Jiashuo Li (@jiasli) from the Azure CLI team on this topic. The missing-dependency may bring complications on Azure CLI's packaging steps in the future. Is it the right price to pay for a smaller installation package? Jiashuo Li (@jiasli) , please also lete HangLei know this.

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions