@@ -310,7 +310,7 @@ public async Task<bool> ValidateCredentials(TargetUri targetUri, Credential cred
310
310
if ( targetUri is null )
311
311
throw new ArgumentNullException ( nameof ( targetUri ) ) ;
312
312
if ( credentials is null )
313
- throw new ArgumentNullException ( nameof ( credentials ) ) ;
313
+ return false ;
314
314
315
315
try
316
316
{
@@ -331,14 +331,31 @@ public async Task<bool> ValidateCredentials(TargetUri targetUri, Credential cred
331
331
332
332
// Even if the service responded, if the issue isn't a 400 class response then
333
333
// the credentials were likely not rejected.
334
- if ( ( int ) response . StatusCode < 400 && ( int ) response . StatusCode >= 500 )
334
+ if ( ( int ) response . StatusCode < 400 || ( int ) response . StatusCode >= 500 )
335
+ {
336
+ Trace . WriteLine ( $ "unable to validate credentials for '{ targetUri } ', unexpected response [{ ( int ) response . StatusCode } { response . ReasonPhrase } ].") ;
337
+
335
338
return true ;
339
+ }
340
+
341
+ Trace . WriteLine ( $ "credential validation for '{ targetUri } ' failed [{ ( int ) response . StatusCode } { response . ReasonPhrase } ].") ;
342
+
343
+ return false ;
336
344
}
337
345
}
338
- catch ( Exception exception )
346
+ catch ( HttpRequestException exception )
339
347
{
348
+ // Since we're unable to invalidate the credentials, return optimistic results.
349
+ // This avoid credential invalidation due to network instability, etc.
350
+ Trace . WriteLine ( $ "unable to validate credentials for '{ targetUri } ', failure occurred before server could respond.") ;
340
351
Trace . WriteException ( exception ) ;
352
+
353
+ return true ;
341
354
}
355
+ catch ( Exception exception )
356
+ {
357
+ Trace . WriteException ( exception ) ;
358
+ } ;
342
359
343
360
Trace . WriteLine ( $ "credential validation for '{ targetUri } ' failed.") ;
344
361
return false ;
@@ -349,7 +366,7 @@ public async Task<bool> ValidateToken(TargetUri targetUri, Token token)
349
366
if ( targetUri is null )
350
367
throw new ArgumentNullException ( nameof ( targetUri ) ) ;
351
368
if ( token is null )
352
- throw new ArgumentNullException ( nameof ( token ) ) ;
369
+ return false ;
353
370
354
371
// Personal access tokens are effectively credentials, treat them as such.
355
372
if ( token . Type == TokenType . Personal )
0 commit comments