-
-
Notifications
You must be signed in to change notification settings - Fork 28
Fix interactive authentication for PowerShell Core 7+ by using system browser #250
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
base: main
Are you sure you want to change the base?
Conversation
…owser Co-authored-by: igoravl <[email protected]>
…detection Co-authored-by: igoravl <[email protected]>
|
P:\Repos\Gh\igoravl\TfsCmdlets> ctfs cloudmotion-projetos -Interactive [Not connected] "Collection" = "cloudmotion-projetos", VERBOSE: [19:17:42.4061] [Connect-TfsTeamProjectCollection] Running [Connect-TfsTeamProjectCollection] with parameter set 'Prompt for credential' and the following implicit and explicit arguments: "Collection" = "cloudmotion-projetos", VERBOSE: [19:17:42.4067] [Connect-TfsTeamProjectCollection] Get currently connected Server "Collection" = "cloudmotion-projetos", VERBOSE: [19:17:42.4083] [Connect-TfsTeamProjectCollection] Using interactive credential |
…g constructor-based dependency injection Co-authored-by: igoravl <[email protected]>
... Fixed the null reference exception by switching from property-based to constructor-based dependency injection for Commit: 9516bd9 |
|
P:\Repos\Gh\igoravl\TfsCmdlets> ctfs cloudmotion-projetos -Verbose -Interactive "Collection" = "cloudmotion-projetos", VERBOSE: [19:31:04.8778] [Connect-TfsTeamProjectCollection] Running [Connect-TfsTeamProjectCollection] with parameter set 'Prompt for credential' and the following implicit and explicit arguments: "Collection" = "cloudmotion-projetos", VERBOSE: [19:31:04.8845] [Connect-TfsTeamProjectCollection] Get currently connected Server "Collection" = "cloudmotion-projetos", VERBOSE: [19:31:04.9042] [Connect-TfsTeamProjectCollection] Using interactive credential |
- Created .github/copilot-instructions.md for Copilot guidance - Added .github/copilot-setup-steps.yml for setup steps - Updated .vscode/settings.json to include Copilot commit message generation instructions
|
Resume investigation on the original error. While on it, check also the following warning in the IDE: 'DesktopExtensions.WithDesktopFeatures(PublicClientApplicationBuilder)' is obsolete: 'Use WithWindowsDesktopFeatures instead. For broker support only, use WithBroker(BrokerOptions) from Microsoft.Identity.Client.Broker package.'CS0618 |
Co-authored-by: igoravl <[email protected]>
Fixed the PowerShell Core detection issue by switching from Commit: 6c0f5cd |
- Updated TfsCmdlets.SourceGenerators.UnitTests.csproj - Added PackageReference for Microsoft.CodeAnalysis.CSharp.Workspaces - Updated TfsCmdlets.SourceGenerators.csproj - Added PackageReference for Microsoft.CodeAnalysis.CSharp.Workspaces - Updated TfsCmdlets.csproj - Added PackageReferences for Microsoft.CodeAnalysis.CSharp.Workspaces, Microsoft.CodeAnalysis.Common, and Microsoft.CodeAnalysis.CSharp
Test Results 2 files 80 suites 44s ⏱️ Results for commit 0e0ab92. ♻️ This comment has been updated with latest results. |
- Created ProcessExtensions class with methods to: - Get parent process ID - Retrieve parent process - Get main window handle recursively - Updated IPowerShellService to include WindowHandle property - Enhanced InteractiveAuthenticationImpl to use WindowHandle - Implemented WindowHandle in PowerShellServiceImpl
Problem
When using interactive authentication (
Connect-TfsTeamProjectCollection -Interactive) in PowerShell Core 7+, users encounter the following error:This prevents users from authenticating interactively in PowerShell Core environments, forcing them to use alternative authentication methods like Personal Access Tokens.
Root Cause
MSAL (Microsoft Authentication Library) by default attempts to create an embedded web view for interactive authentication, which requires a proper window handle. In PowerShell Core, especially in console environments or on non-Windows platforms, no suitable window handle is available, causing the authentication to fail.
Solution
This PR implements PowerShell edition detection and configures MSAL appropriately for each environment:
.WithUseEmbeddedWebView(false))Technical Changes
Core Implementation
IRuntimeUtildependency injection toInteractiveAuthenticationImplfor consistent PowerShell edition detectionIsPowerShellCore()method usingRuntimeUtil.Platform.Equals("Core").WithUseEmbeddedWebView(false)for PowerShell CoreDocumentation Update
CommonHelpText.psd1to reflect that interactive authentication now supports both Windows PowerShell and PowerShell CoreCode Example
Impact
NewCredentialclassTesting
The fix enables MSAL to open the system browser for authentication instead of attempting to create an embedded web view that requires window handles unavailable in PowerShell Core environments.
Fixes #249.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.