Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Commit 44f1866

Browse files
author
J Wyman
authored
Merge pull request #690 from whoisj/v1.17/no-delete
vsts: null credentials are invalid.
2 parents f0d43b3 + 94259ca commit 44f1866

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

VisualStudioTeamServices.Authentication/Src/Authority.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public async Task<bool> ValidateCredentials(TargetUri targetUri, Credential cred
310310
if (targetUri is null)
311311
throw new ArgumentNullException(nameof(targetUri));
312312
if (credentials is null)
313-
throw new ArgumentNullException(nameof(credentials));
313+
return false;
314314

315315
try
316316
{
@@ -331,14 +331,31 @@ public async Task<bool> ValidateCredentials(TargetUri targetUri, Credential cred
331331

332332
// Even if the service responded, if the issue isn't a 400 class response then
333333
// 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+
335338
return true;
339+
}
340+
341+
Trace.WriteLine($"credential validation for '{targetUri}' failed [{(int)response.StatusCode} {response.ReasonPhrase}].");
342+
343+
return false;
336344
}
337345
}
338-
catch (Exception exception)
346+
catch (HttpRequestException exception)
339347
{
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.");
340351
Trace.WriteException(exception);
352+
353+
return true;
341354
}
355+
catch (Exception exception)
356+
{
357+
Trace.WriteException(exception);
358+
};
342359

343360
Trace.WriteLine($"credential validation for '{targetUri}' failed.");
344361
return false;
@@ -349,7 +366,7 @@ public async Task<bool> ValidateToken(TargetUri targetUri, Token token)
349366
if (targetUri is null)
350367
throw new ArgumentNullException(nameof(targetUri));
351368
if (token is null)
352-
throw new ArgumentNullException(nameof(token));
369+
return false;
353370

354371
// Personal access tokens are effectively credentials, treat them as such.
355372
if (token.Type == TokenType.Personal)

0 commit comments

Comments
 (0)