in CredentialProvider.Microsoft/RequestHandlers/GetAuthenticationCredentialsRequestHandler.cs [45:119]
public override async Task<GetAuthenticationCredentialsResponse> HandleRequestAsync(GetAuthenticationCredentialsRequest request)
{
Logger.Verbose(string.Format(Resources.HandlingAuthRequest, request.Uri.AbsoluteUri, request.IsRetry, request.IsNonInteractive, request.CanShowDialog));
if (request?.Uri == null)
{
return new GetAuthenticationCredentialsResponse(
username: null,
password: null,
message: Resources.RequestUriNull,
authenticationTypes: null,
responseCode: MessageResponseCode.Error);
}
Logger.Verbose(string.Format(Resources.Uri, request.Uri.AbsoluteUri));
foreach (ICredentialProvider credentialProvider in credentialProviders)
{
if (await credentialProvider.CanProvideCredentialsAsync(request.Uri) == false)
{
Logger.Verbose(string.Format(Resources.SkippingCredentialProvider, credentialProvider, request.Uri.AbsoluteUri));
continue;
}
Logger.Verbose(string.Format(Resources.UsingCredentialProvider, credentialProvider, request.Uri.AbsoluteUri));
if (credentialProvider.IsCachable && TryCache(request, out string cachedToken))
{
return new GetAuthenticationCredentialsResponse(
username: "VssSessionToken",
password: cachedToken,
message: null,
authenticationTypes: new List<string> { "Basic" },
responseCode: MessageResponseCode.Success);
}
try
{
GetAuthenticationCredentialsResponse response = await credentialProvider.HandleRequestAsync(request, CancellationToken).ConfigureAwait(continueOnCapturedContext: false);
if (response != null && response.ResponseCode == MessageResponseCode.Success)
{
if (cache != null && credentialProvider.IsCachable)
{
Logger.Verbose(string.Format(Resources.CachingSessionToken, request.Uri.AbsoluteUri));
cache[request.Uri] = response.Password;
}
return response;
}
else if (!string.IsNullOrWhiteSpace(response?.Message))
{
Logger.Verbose(response.Message);
}
}
catch (Exception e)
{
Logger.Error(string.Format(Resources.AcquireSessionTokenFailed, e.ToString()));
return new GetAuthenticationCredentialsResponse(
username: null,
password: null,
message: e.Message,
authenticationTypes: null,
responseCode: MessageResponseCode.Error);
}
}
Logger.Verbose(Resources.CredentialsNotFound);
return new GetAuthenticationCredentialsResponse(
username: null,
password: null,
message: null,
authenticationTypes: null,
responseCode: MessageResponseCode.NotFound);
}