@@ -85,7 +85,7 @@ private record TokenResponse(string? token, string? access_token, int? expires_i
85
85
/// <param name="scope"></param>
86
86
/// <param name="cancellationToken"></param>
87
87
/// <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 )
89
89
{
90
90
// Allow overrides for auth via environment variables
91
91
string ? credU = Environment . GetEnvironmentVariable ( ContainerHelpers . HostObjectUser ) ;
@@ -102,26 +102,26 @@ private record TokenResponse(string? token, string? access_token, int? expires_i
102
102
{
103
103
try
104
104
{
105
- privateRepoCreds = await CredsProvider . GetCredentialsAsync ( uri . Host ) ;
105
+ privateRepoCreds = await CredsProvider . GetCredentialsAsync ( registry ) ;
106
106
}
107
107
catch ( Exception e )
108
108
{
109
- throw new CredentialRetrievalException ( uri . Host , e ) ;
109
+ throw new CredentialRetrievalException ( registry , e ) ;
110
110
}
111
111
}
112
112
113
113
if ( scheme is "Basic" )
114
114
{
115
115
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 ) ;
117
117
}
118
118
else if ( scheme is "Bearer" )
119
119
{
120
120
// use those creds when calling the token provider
121
121
var header = privateRepoCreds . Username == "<token>"
122
122
? new AuthenticationHeaderValue ( "Bearer" , privateRepoCreds . Password )
123
123
: new AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( Encoding . ASCII . GetBytes ( $ "{ privateRepoCreds . Username } :{ privateRepoCreds . Password } ") ) ) ;
124
- var builder = new UriBuilder ( uri ) ;
124
+ var builder = new UriBuilder ( realm ) ;
125
125
var queryDict = System . Web . HttpUtility . ParseQueryString ( "" ) ;
126
126
queryDict [ "service" ] = service ;
127
127
if ( scope is string s )
@@ -143,7 +143,7 @@ private record TokenResponse(string? token, string? access_token, int? expires_i
143
143
144
144
// save the retrieved token in the cache
145
145
var bearerAuth = new AuthenticationHeaderValue ( "Bearer" , token . ResolvedToken ) ;
146
- return AuthHeaderCache . AddOrUpdate ( uri , bearerAuth ) ;
146
+ return AuthHeaderCache . AddOrUpdate ( realm , bearerAuth ) ;
147
147
}
148
148
else
149
149
{
@@ -177,7 +177,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
177
177
}
178
178
else if ( response is { StatusCode : HttpStatusCode . Unauthorized } && TryParseAuthenticationInfo ( response , out string ? scheme , out AuthInfo ? authInfo ) )
179
179
{
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 )
181
181
{
182
182
request . Headers . Authorization = AuthHeaderCache . AddOrUpdate ( request . RequestUri , authentication ) ;
183
183
return await base . SendAsync ( request , cancellationToken ) ;
0 commit comments