Skip to content

CP -> releases/2.0.2 Fix silent auth failure in WSL caused by broker token provider (#675) - #676

Merged
embetten merged 1 commit into
releases/2.0.2from
users/embetten/cherry-pick-675-to-2.0.2
May 5, 2026
Merged

embetten merged 1 commit into
releases/2.0.2from
users/embetten/cherry-pick-675-to-2.0.2

Conversation

@embetten

@embetten embetten commented May 5, 2026

Copy link
Copy Markdown
Contributor

WSL reports as Linux but has no msalruntime daemon, causing MsalSilentTokenProvider to fail when using appInteractiveBroker.

  • Add PlatformInformation.IsWSL() to detect WSL via RuntimeInformation.IsOSPlatform(Linux) and WSL_DISTRO_NAME env var
  • Use non-broker app for silent auth on WSL, matching behavior before 0cddac6
  • Add tests for WSL and non-WSL silent auth provider selection

Problem

Commit #664 (#666) changed MsalSilentTokenProviderto use appInteractiveBroker ?? app so that the broker's token cache is queried on silent auth. This works correctly on Windows and macOS, but breaks Windows Subsystem for Linux (WSL) due to stdout corruption from MSAL linux broker subprocesses.
Related MSAL issue:
AzureAD/microsoft-authentication-library-for-dotnet#5979

work around until MSAL responds

Add PlatformInformation.IsWSL() which returns true when the runtime OS is Linux and the WSL_DISTRO_NAME environment variable is set (always present in WSL sessions, never set on native Linux/macOS/Windows). In MsalTokenProviders.Get() use the non-broker app for silent auth when running in WSL, restoring the pre-#664 behavior for WSL users while keeping broker-accelerated silent auth on Windows and macOS.

Testing

Added unit tests covering silent provider selection under WSL and non-WSL conditions with both empty and warm MSAL caches.

WSL reports as Linux but has no msalruntime daemon, causing
MsalSilentTokenProvider to fail when using appInteractiveBroker.

- Add PlatformInformation.IsWSL() to detect WSL via
RuntimeInformation.IsOSPlatform(Linux) and WSL_DISTRO_NAME env var
- Use non-broker app for silent auth on WSL, matching behavior before
0cddac6
- Add tests for WSL and non-WSL silent auth provider selection

### Problem
Commit #664 (#666) changed `MsalSilentTokenProvidert`o use
`appInteractiveBroker ?? app` so that the broker's token cache is
queried on silent auth. This works correctly on Windows and macOS, but
breaks Windows Subsystem for Linux (WSL) due to stdout corruption from
MSAL linux broker subprocesses.
Related MSAL issue:
AzureAD/microsoft-authentication-library-for-dotnet#5979

### work around until MSAL responds
Add `PlatformInformation.IsWSL()` which returns true when the runtime OS
is Linux and the WSL_DISTRO_NAME environment variable is set (always
present in WSL sessions, never set on native Linux/macOS/Windows).
In `MsalTokenProviders.Get()` use the non-broker app for silent auth
when running in WSL, restoring the pre-#664 behavior for WSL users while
keeping broker-accelerated silent auth on Windows and macOS.

### Testing
Added unit tests covering silent provider selection under WSL and
non-WSL conditions with both empty and warm MSAL caches.
@embetten
embetten merged commit d0f3d8d into releases/2.0.2 May 5, 2026
55 checks passed
@embetten
embetten deleted the users/embetten/cherry-pick-675-to-2.0.2 branch May 5, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants