Reduce repeated Graph sign-in prompts by caching delegated tokens and unifying auth paths#136
Closed
mengyimicro wants to merge 3 commits intomainfrom
Closed
Reduce repeated Graph sign-in prompts by caching delegated tokens and unifying auth paths#136mengyimicro wants to merge 3 commits intomainfrom
mengyimicro wants to merge 3 commits intomainfrom
Conversation
… unifying auth paths
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces the number of Microsoft sign-in prompts during setup by implementing token caching and unifying authentication paths for Graph API operations. Previously, each Graph operation could trigger a new PowerShell session and require re-authentication, resulting in 20+ sign-in popups during setup in a new tenant.
Key changes:
- Added in-memory delegated token caching in
MicrosoftGraphTokenProviderwith JWT expiration tracking to reuse tokens across multiple Graph calls - Fixed
GraphApiServicemethods to accept and pass throughscopesparameters consistently, preventing fallback to Azure CLI authentication - Implemented pre-warming of delegated Graph authentication in
SetupHelpersto ensure all permission operations use a single authentication session
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
MicrosoftGraphTokenProvider.cs |
Implements token caching with single-flight locking, JWT expiry parsing, and cache key generation based on tenant/client/scopes |
GraphApiService.cs |
Adds scopes parameter to service principal lookup and creation methods to support delegated authentication consistently |
SetupHelpers.cs |
Pre-warms delegated token at the start of permission setup to ensure consistent auth path across all Graph operations |
PublishHelpersTests.cs |
Updates mock method signatures to match new scopes parameter in service principal methods |
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
pontemonti
previously approved these changes
Dec 27, 2025
tmlsousa
reviewed
Dec 29, 2025
src/Microsoft.Agents.A365.DevTools.Cli/Commands/SetupSubcommands/SetupHelpers.cs
Outdated
Show resolved
Hide resolved
tmlsousa
reviewed
Dec 29, 2025
src/Microsoft.Agents.A365.DevTools.Cli/Commands/SetupSubcommands/SetupHelpers.cs
Outdated
Show resolved
Hide resolved
tmlsousa
reviewed
Dec 29, 2025
src/Microsoft.Agents.A365.DevTools.Cli/Commands/SetupSubcommands/SetupHelpers.cs
Outdated
Show resolved
Hide resolved
tmlsousa
previously approved these changes
Dec 29, 2025
0911cd1
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Commands/SetupSubcommands/SetupHelpers.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
pontemonti
approved these changes
Dec 29, 2025
tmlsousa
approved these changes
Dec 29, 2025
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Commands/SetupSubcommands/SetupHelpers.cs
Show resolved
Hide resolved
Contributor
Author
|
Close this PR since hit github bug. use the latest PR for merge the fix code: #139 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running a365 setup all in a new tenant triggers 20+ Microsoft sign-in popups during execution.
Root causes:
This resulted in a poor CLI experience and made setup appear unreliable.
Fix
This PR reduces interactive sign-in prompts by reusing delegated Graph tokens and ensuring a single auth path during setup.
Key changes:
Test