Optimize Auth flow and switch from DCF to Interactive Authentication#172
Merged
mengyimicro merged 3 commits intomainfrom Jan 24, 2026
Merged
Optimize Auth flow and switch from DCF to Interactive Authentication#172mengyimicro merged 3 commits intomainfrom
mengyimicro merged 3 commits intomainfrom
Conversation
Remove Device Code Flow (DCF) across the entire CLI to comply with production tenant security policies. Replace all DCF usage with interactive browser authentication (WAM on Windows, browser on other platforms). Changes: - AuthenticationService: Change default useInteractiveBrowser from false to true - MicrosoftGraphTokenProvider: Change default useDeviceCode from true to false - AzureWebAppCreator: Remove ExcludeInteractiveBrowserCredential flag to allow browser auth - InteractiveGraphAuthService: Remove device code fallback, use browser-only authentication Token caching remains in place to minimize the number of authentication prompts to 1-2 times per session. All 844 tests passing (17 intentionally skipped). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive documentation and better logging to clarify the authentication strategy used across all CLI commands. This helps users understand the 1-2 authentication prompt experience. Changes: - AuthenticationService: Add detailed class-level documentation explaining: * Interactive browser authentication (no DCF) * Token caching strategy and location * Multi-command workflow (1-2 prompts total) * Cache expiration and automatic refresh - GraphApiService: Improve EnsureGraphHeadersAsync with: * Clear authentication strategy comments * Better debug logging for auth method selection * Improved error messages with actionable guidance * Explicit handling for scopes vs Azure CLI fallback - MicrosoftGraphTokenProvider: Document: * Interactive browser as default (not device code) * In-memory and persistent caching * Integration with overall CLI auth strategy Result: Users clearly understand why they only authenticate 1-2 times for entire CLI usage, with tokens cached across all commands and sessions. All 844 tests passing (17 intentionally skipped). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request switches the Agent365-devTools CLI from Device Code Flow (DCF) to Interactive Browser Authentication to comply with production tenant security policies that discourage DCF usage. The change implements browser-based authentication using MsalBrowserCredential (WAM on Windows, browser on other platforms) while maintaining comprehensive token caching to minimize authentication prompts.
Changes:
- Modified default authentication method from Device Code Flow to Interactive Browser Authentication across all authentication services
- Removed device code fallback logic in favor of clear error messages when browser authentication fails
- Enhanced documentation explaining authentication strategy, token caching location, cache key format, and expected user experience (1-2 prompts for entire workflow)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| AuthenticationService.cs | Changed default useInteractiveBrowser parameter to true in two public methods; added comprehensive class-level documentation about authentication strategy and token caching |
| MicrosoftGraphTokenProvider.cs | Changed default useDeviceCode parameter to false; added documentation explaining interactive browser as default with token caching details |
| AzureWebAppCreator.cs | Enabled interactive browser credential in DefaultAzureCredential chain by setting ExcludeInteractiveBrowserCredential to false; updated credential chain documentation |
| InteractiveGraphAuthService.cs | Removed ~68 lines of device code fallback logic; infrastructure/connectivity errors now throw immediately with clear error messages |
| GraphApiService.cs | Enhanced EnsureGraphHeadersAsync with clearer authentication strategy comments and improved debug logging for auth method selection |
pontemonti
reviewed
Jan 22, 2026
src/Microsoft.Agents.A365.DevTools.Cli/Services/Internal/MicrosoftGraphTokenProvider.cs
Show resolved
Hide resolved
pontemonti
previously approved these changes
Jan 22, 2026
Minor improvements based on review: 1. Update endpoint cleanup guidance to include --endpoint-only flag 2. Refine authentication documentation wording from "interactive browser" to "interactive" Changes: - BlueprintSubcommand: Fix cleanup command example to use 'a365 cleanup blueprint --endpoint-only' - AuthenticationService: Update documentation to use "interactive authentication" terminology Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
pontemonti
approved these changes
Jan 23, 2026
tmlsousa
approved these changes
Jan 23, 2026
sellakumaran
pushed a commit
that referenced
this pull request
Feb 27, 2026
…172) * Switch from Device Code Flow to Interactive Browser Authentication Remove Device Code Flow (DCF) across the entire CLI to comply with production tenant security policies. Replace all DCF usage with interactive browser authentication (WAM on Windows, browser on other platforms). Changes: - AuthenticationService: Change default useInteractiveBrowser from false to true - MicrosoftGraphTokenProvider: Change default useDeviceCode from true to false - AzureWebAppCreator: Remove ExcludeInteractiveBrowserCredential flag to allow browser auth - InteractiveGraphAuthService: Remove device code fallback, use browser-only authentication Token caching remains in place to minimize the number of authentication prompts to 1-2 times per session. All 844 tests passing (17 intentionally skipped). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Improve authentication flow logging and documentation Add comprehensive documentation and better logging to clarify the authentication strategy used across all CLI commands. This helps users understand the 1-2 authentication prompt experience. Changes: - AuthenticationService: Add detailed class-level documentation explaining: * Interactive browser authentication (no DCF) * Token caching strategy and location * Multi-command workflow (1-2 prompts total) * Cache expiration and automatic refresh - GraphApiService: Improve EnsureGraphHeadersAsync with: * Clear authentication strategy comments * Better debug logging for auth method selection * Improved error messages with actionable guidance * Explicit handling for scopes vs Azure CLI fallback - MicrosoftGraphTokenProvider: Document: * Interactive browser as default (not device code) * In-memory and persistent caching * Integration with overall CLI auth strategy Result: Users clearly understand why they only authenticate 1-2 times for entire CLI usage, with tokens cached across all commands and sessions. All 844 tests passing (17 intentionally skipped). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Fix cleanup command documentation and refine authentication terminology Minor improvements based on review: 1. Update endpoint cleanup guidance to include --endpoint-only flag 2. Refine authentication documentation wording from "interactive browser" to "interactive" Changes: - BlueprintSubcommand: Fix cleanup command example to use 'a365 cleanup blueprint --endpoint-only' - AuthenticationService: Update documentation to use "interactive authentication" terminology Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
Summary
Switch from Device Code Flow (DCF) to Interactive Browser Authentication across the entire Agent365-devTools CLI to comply with production tenant security policies that discourage DCF usage.
This PR implements interactive browser authentication (WAM on Windows, browser on other platforms) while maintaining comprehensive token caching to ensure users only authenticate 1-2 times total for all CLI commands.
Changes
Authentication Method Changes (4 files)
AuthenticationService.cs
useInteractiveBrowserparameter fromfalsetotrue(2 methods)MsalBrowserCredentialby default instead ofDeviceCodeCredentialMicrosoftGraphTokenProvider.cs
useDeviceCodeparameter fromtruetofalseAzureWebAppCreator.cs
ExcludeInteractiveBrowserCredentialfromtruetofalseDefaultAzureCredentialto use interactive browser when Azure CLI is not authenticatedInteractiveGraphAuthService.cs
Documentation & Logging Improvements (3 files)
AuthenticationService.cs - Added comprehensive documentation:
%LocalApplicationData%\Agent365\token-cache.json{resourceUrl}:tenant:{tenantId}GraphApiService.cs - Enhanced
EnsureGraphHeadersAsync:MicrosoftGraphTokenProvider.cs - Added documentation:
User Experience
Authentication Prompts
First-Time Run: 2 prompts
Subsequent Runs: 0 prompts (tokens cached and reused)
Token Caching Strategy
azCLI (~1 hour persistence)%LocalApplicationData%\Agent365\token-cache.jsonExample Workflow