Skip to content

Commit 8b868ee

Browse files
authored
Merge pull request #286 from dotnet/diff-names
2 parents e569784 + 85ce19f commit 8b868ee

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private record TokenResponse(string? token, string? access_token, int? expires_i
8585
/// <param name="scope"></param>
8686
/// <param name="cancellationToken"></param>
8787
/// <returns></returns>
88-
private async Task<AuthenticationHeaderValue?> GetAuthenticationAsync(string scheme, Uri uri, string service, string? scope, CancellationToken cancellationToken)
88+
private async Task<AuthenticationHeaderValue?> GetAuthenticationAsync(string registry, string scheme, Uri realm, string service, string? scope, CancellationToken cancellationToken)
8989
{
9090
// Allow overrides for auth via environment variables
9191
string? credU = Environment.GetEnvironmentVariable(ContainerHelpers.HostObjectUser);
@@ -102,26 +102,26 @@ private record TokenResponse(string? token, string? access_token, int? expires_i
102102
{
103103
try
104104
{
105-
privateRepoCreds = await CredsProvider.GetCredentialsAsync(uri.Host);
105+
privateRepoCreds = await CredsProvider.GetCredentialsAsync(registry);
106106
}
107107
catch (Exception e)
108108
{
109-
throw new CredentialRetrievalException(uri.Host, e);
109+
throw new CredentialRetrievalException(registry, e);
110110
}
111111
}
112112

113113
if (scheme is "Basic")
114114
{
115115
var basicAuth = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{privateRepoCreds.Username}:{privateRepoCreds.Password}")));
116-
return AuthHeaderCache.AddOrUpdate(uri, basicAuth);
116+
return AuthHeaderCache.AddOrUpdate(realm, basicAuth);
117117
}
118118
else if (scheme is "Bearer")
119119
{
120120
// use those creds when calling the token provider
121121
var header = privateRepoCreds.Username == "<token>"
122122
? new AuthenticationHeaderValue("Bearer", privateRepoCreds.Password)
123123
: new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{privateRepoCreds.Username}:{privateRepoCreds.Password}")));
124-
var builder = new UriBuilder(uri);
124+
var builder = new UriBuilder(realm);
125125
var queryDict = System.Web.HttpUtility.ParseQueryString("");
126126
queryDict["service"] = service;
127127
if (scope is string s)
@@ -143,7 +143,7 @@ private record TokenResponse(string? token, string? access_token, int? expires_i
143143

144144
// save the retrieved token in the cache
145145
var bearerAuth = new AuthenticationHeaderValue("Bearer", token.ResolvedToken);
146-
return AuthHeaderCache.AddOrUpdate(uri, bearerAuth);
146+
return AuthHeaderCache.AddOrUpdate(realm, bearerAuth);
147147
}
148148
else
149149
{
@@ -177,7 +177,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
177177
}
178178
else if (response is { StatusCode: HttpStatusCode.Unauthorized } && TryParseAuthenticationInfo(response, out string? scheme, out AuthInfo? authInfo))
179179
{
180-
if (await GetAuthenticationAsync(scheme, authInfo.Realm, authInfo.Service, authInfo.Scope, cancellationToken) is AuthenticationHeaderValue authentication)
180+
if (await GetAuthenticationAsync(request.RequestUri.Host, scheme, authInfo.Realm, authInfo.Service, authInfo.Scope, cancellationToken) is AuthenticationHeaderValue authentication)
181181
{
182182
request.Headers.Authorization = AuthHeaderCache.AddOrUpdate(request.RequestUri, authentication);
183183
return await base.SendAsync(request, cancellationToken);

0 commit comments

Comments
 (0)