in CredentialProvider.Microsoft/CredentialProviders/VstsBuildTaskServiceEndpoint/VstsBuildTaskServiceEndpointCredentialProvider.cs [103:152]
private Dictionary<string, EndpointCredentials> ParseJsonToDictionary()
{
string feedEndPointsJson = Environment.GetEnvironmentVariable(EnvUtil.BuildTaskExternalEndpoints);
try
{
// Parse JSON from VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
Verbose(Resources.ParsingJson);
Dictionary<string, EndpointCredentials> credsResult = new Dictionary<string, EndpointCredentials>(StringComparer.OrdinalIgnoreCase);
EndpointCredentialsContainer endpointCredentials = JsonConvert.DeserializeObject<EndpointCredentialsContainer>(feedEndPointsJson);
if (endpointCredentials == null)
{
Verbose(Resources.NoEndpointsFound);
return credsResult;
}
foreach (EndpointCredentials credentials in endpointCredentials.EndpointCredentials)
{
if (credentials == null)
{
Verbose(Resources.EndpointParseFailure);
break;
}
if (credentials.Username == null)
{
credentials.Username = "VssSessionToken";
}
if (!Uri.TryCreate(credentials.Endpoint, UriKind.Absolute, out var endpointUri))
{
Verbose(Resources.EndpointParseFailure);
break;
}
var urlEncodedEndpoint = endpointUri.AbsoluteUri;
if (!credsResult.ContainsKey(urlEncodedEndpoint))
{
credsResult.Add(urlEncodedEndpoint, credentials);
}
}
return credsResult;
}
catch (Exception e)
{
Verbose(string.Format(Resources.VstsBuildTaskExternalCredentialCredentialProviderError, e));
throw;
}
}