Skip to content

Add -LoginHint parameter to Connect-MgGraph (closes #3605)#3662

Open
gavinbarron wants to merge 3 commits into
mainfrom
gavinbarron/connect-mggraph-loginhint
Open

Add -LoginHint parameter to Connect-MgGraph (closes #3605)#3662
gavinbarron wants to merge 3 commits into
mainfrom
gavinbarron/connect-mggraph-loginhint

Conversation

@gavinbarron

Copy link
Copy Markdown
Member

Summary

Adds a new optional -LoginHint parameter to Connect-MgGraph (UserParameterSet) that pre-populates the account (login_hint) shown during interactive browser / WAM sign-in. This lets callers go straight to the preferred sign-in method for a known account instead of navigating the WAM account picker.

Connect-MgGraph -Scopes "User.Read.All" -LoginHint "user@contoso.com"

Closes #3605

Changes

  • -LoginHint parameter on Connect-MgGraph, flowed through IAuthContext / AuthContext onto InteractiveBrowserCredentialOptions.LoginHint.
  • Per-account auth record persistence: the persisted AuthenticationRecord is keyed by a hashed, normalized login hint so repeat sign-ins for the same account are picker-free, while a different user's record is never silently reused. An existing shared record is migrated to a per-account record only when its username matches the supplied hint.
  • Scoped sign-out: cache clearing and auth-record deletion on Disconnect-MgGraph are scoped to the correct per-account record.
  • Tests: new AuthenticationHelpers unit tests and Connect-MgGraph parameter-set tests.
  • Docs: example added to Connect-MgGraph docs/help (plus regenerated help/docs metadata).

Behavior notes

On Windows, WAM may still display the account picker on the first sign-in for an account; later sign-ins with the same -LoginHint are silent.

Validation

  • dotnet test (net8.0) on Microsoft.Graph.Authentication.Test, filtered to AuthenticationHelpers: 26 passed, 0 failed.

Notes for reviewers

  • This PR also includes regenerated docs/help and module metadata (version fields, .psd1 date, unrelated cmdlet doc regeneration) that were produced by the local build tooling and are part of the current working tree.
  • The autorest.powershell submodule pointer change was intentionally excluded from this PR.

Adds a new optional -LoginHint parameter to Connect-MgGraph (UserParameterSet)
that pre-populates the account (login_hint) shown during interactive browser /
WAM sign-in. This lets callers go straight to the preferred sign-in method for a
known account instead of navigating the WAM account picker.

- Flow the login hint through IAuthContext / AuthContext and onto
  InteractiveBrowserCredentialOptions.LoginHint.
- Persist a per-account AuthenticationRecord (keyed by a hashed, normalized login
  hint) so repeat sign-ins for the same account are picker-free, while never
  silently reusing a different user's record. Existing shared records are migrated
  to per-account records only when the username matches the supplied hint.
- Scope cache clearing and auth-record deletion on Disconnect-MgGraph to the
  correct per-account record.
- Add unit tests and parameter-set tests, plus docs and an example.

Closes #3605

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 04338979-a6b1-4abe-9ffe-42eb16b07442
@gavinbarron
gavinbarron requested a review from a team as a code owner July 16, 2026 18:35
Add the missing -LoginHint parameter block to the Connect-MgGraph markdown
docs and generated MAML help (syntax + parameter list), which the earlier
docs regeneration omitted because the module DLL predated the new parameter.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 04338979-a6b1-4abe-9ffe-42eb16b07442

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional -LoginHint parameter to Connect-MgGraph to pre-populate the account during interactive sign-in (browser/WAM) and introduces per-account persisted AuthenticationRecord handling so records aren’t silently reused across different users. The PR also includes regenerated help/docs artifacts and version metadata updates.

Changes:

  • Add -LoginHint to Connect-MgGraph (UserParameterSet) and flow it through IAuthContext/AuthContext to InteractiveBrowserCredentialOptions.LoginHint.
  • Introduce per-account auth record persistence keyed by a normalized+hashed login hint, with legacy-record migration logic and scoped sign-out behavior.
  • Add/extend tests and regenerate documentation/help metadata.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/Authentication/examples/Connect-MgGraph.md Adds a usage example for -LoginHint.
src/Authentication/docs/Connect-MgGraph.md Documents -LoginHint and updates examples/syntax (plus regenerated content).
src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs Adds -LoginHint parameter and maps it into the auth context.
src/Authentication/Authentication.Core/Interfaces/IAuthContext.cs Extends auth context contract with LoginHint.
src/Authentication/Authentication/Models/AuthContext.cs Implements LoginHint on the concrete auth context.
src/Authentication/Authentication.Core/Utilities/AuthenticationHelpers.cs Applies LoginHint to interactive credential options and introduces per-account auth record resolution/scoped logout.
src/Authentication/Authentication.Test/Helpers/AuthenticationHelpersTests.cs Adds unit tests for per-account auth record resolution and login-hint behavior.
src/Authentication/Authentication/test/Connect-MgGraph.Tests.ps1 Adds parameter-set coverage for LoginHint.
src/Authentication/docs/Disconnect-MgGraph.md Regenerated help content (e.g., parameter ordering/ProgressAction).
src/Authentication/docs/Get-MgContext.md Regenerated help content (ProgressAction).
src/Authentication/docs/Get-MgEnvironment.md Regenerated help content and updated environment table.
src/Authentication/docs/Get-MgGraphOption.md Regenerated help content (ProgressAction and notes).
src/Authentication/docs/Get-MgRequestContext.md Regenerated help content (ProgressAction).
src/Authentication/docs/Invoke-MgGraphRequest.md Regenerated help content (ProgressAction).
src/Authentication/docs/Set-MgEnvironment.md Regenerated help content (ProgressAction).
src/Authentication/docs/Remove-MgEnvironment.md Regenerated help content (ProgressAction/formatting).
src/Authentication/docs/Add-MgEnvironment.md Regenerated help content (ProgressAction/formatting).
src/Authentication/docs/Set-MgGraphOption.md Regenerated help content and new sovereign-cloud example.
src/Authentication/docs/Set-MgRequestContext.md Regenerated help content (ProgressAction/formatting).
src/Authentication/docs/Microsoft.Graph.Authentication.md Regenerated module landing page metadata/content.
src/Authentication/Authentication/Constants.cs Adds help message text for LoginHint.
src/Authentication/Authentication/Microsoft.Graph.Authentication-help.xml Regenerated cmdlet help XML (formatting and content updates).
src/Authentication/Authentication/Microsoft.Graph.Authentication.dll-Help.xml Regenerated external help XML (includes new params and examples).
src/Authentication/Authentication/Microsoft.Graph.Authentication.psd1 Regenerated module manifest metadata/version.
src/Authentication/Authentication/Microsoft.Graph.Authentication.nuspec Updates package version.
src/Authentication/Authentication/Microsoft.Graph.Authentication.csproj Updates assembly/package version.
src/Authentication/Authentication.Test/Microsoft.Graph.Authentication.Test.csproj Updates test assembly version/metadata formatting.
src/Authentication/Authentication.Core/Microsoft.Graph.Authentication.Core.csproj Updates core library version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs Outdated
Comment thread src/Authentication/docs/Microsoft.Graph.Authentication.md Outdated
Comment thread src/Authentication/Authentication/Microsoft.Graph.Authentication.dll-Help.xml Outdated
Comment thread src/Authentication/Authentication/Microsoft.Graph.Authentication.dll-Help.xml Outdated
Comment thread src/Authentication/Authentication/Microsoft.Graph.Authentication.dll-Help.xml Outdated
Comment thread src/Authentication/Authentication/Microsoft.Graph.Authentication.dll-Help.xml Outdated
Comment thread src/Authentication/Authentication/Microsoft.Graph.Authentication-help.xml Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

Support for pre-providing username to connect-mggraph

2 participants