Skip to content

Commit bb914a3

Browse files
lewingCopilot
andcommitted
Skip browser retry after persistence-fallback recreation
After RecreateCredentialsWithoutPersistence() rebuilds both credentials, CacheAuthenticationRecord retries Authenticate(). The retry was re-entering the InteractiveBrowserCredential path even though the first attempt had already proved the browser flow was unavailable in this environment (the _isDeviceCodeFallback flag was set, but only GetTokenCore checked it — Authenticate did not). On headless WSL the browser credential opens a Windows-side browser but the OAuth redirect to http://localhost:XXXX cannot reach the WSL-side listener, so the second InteractiveBrowserCredential.Authenticate call hangs forever. The device code prompt never gets a chance to print. Honor _isDeviceCodeFallback at the top of Authenticate so the second call goes straight to DeviceCodeCredential. With this fix, "darc login" on WSL prints the device code + URL immediately on the retry instead of hanging. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 02ddec4 commit bb914a3

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/Maestro/Maestro.Common/AppCredentials/CachedInteractiveBrowserCredential.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ private void CacheAuthenticationRecord(TokenRequestContext requestContext, Cance
192192

193193
private AuthenticationRecord Authenticate(TokenRequestContext requestContext, CancellationToken cancellationToken)
194194
{
195+
// If a previous attempt already proved the browser flow is unavailable in this
196+
// environment (e.g. headless WSL / no GUI), skip straight to device code. Without
197+
// this, the retry after RecreateCredentialsWithoutPersistence() would re-enter the
198+
// browser path and hang waiting for an OAuth redirect that will never arrive.
199+
if (Volatile.Read(ref _isDeviceCodeFallback) == 1)
200+
{
201+
_logger.LogInformation("Using device code authentication (browser flow previously unavailable)...");
202+
return _deviceCodeCredential.Authenticate(requestContext, cancellationToken);
203+
}
204+
195205
try
196206
{
197207
_logger.LogInformation("Waiting for authentication in the browser...");

0 commit comments

Comments
 (0)