github / github/app

WAM interactive browser auth stops working mid-session when running PowerShell scripts via background terminal

Open
#1,801 0 comments 0 reactions 0 assignees View on GitHub
Bugs
Dominant language
No language data
Stars
2.1k
Forks
153
PR merge metrics
No merged PRs in 30d

Description

Short summary
PowerShell scripts using Connect-MgGraph (Microsoft Graph SDK) authenticate successfully via WAM on first run, but fail with "A window handle must be configured" later in the same session after terminal canvas panels are opened/closed.

Affected version or release
Latest (updated 2026-07-09)

Installation context
Windows desktop app, background terminal used to run PowerShell scripts via agent session

What happened?
When running PowerShell scripts that call Connect-MgGraph with interactive browser auth via the Copilot app background terminal, WAM authentication worked correctly on first run. Later in the same session — after opening and closing terminal canvas panels — the same scripts started failing immediately with:

InteractiveBrowserCredential authentication failed: A window handle must be configured.
See https://aka.ms/msal-net-wam#parent-window-handles

The WAM browser prompt no longer appears at all; it fails without waiting for user interaction. The background PowerShell process appears to lose its window handle mid-session, likely caused by terminal canvas lifecycle events. Workaround is to use -UseDeviceCode on Connect-MgGraph, but interactive browser auth should remain stable throughout a session.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with Connect-MgGraph in the background PowerShell terminal, then open and close terminal canvas panels before retrying interactive browser authentication. Investigate how the background terminal and terminal canvas lifecycle preserve the WAM window handle. Done means interactive browser authentication continues to show its prompt and succeeds throughout the session without requiring -UseDeviceCode.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
authentication, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.