@@ -177,19 +177,19 @@ func (c *Client) Do(originalReq *http.Request) (*http.Response, error) {
177
177
// attempt cached auth token
178
178
var attemptedKey string
179
179
cache := c .cache ()
180
- registry := originalReq .Host
181
- scheme , err := cache .GetScheme (ctx , registry )
180
+ host := originalReq .Host
181
+ scheme , err := cache .GetScheme (ctx , host )
182
182
if err == nil {
183
183
switch scheme {
184
184
case SchemeBasic :
185
- token , err := cache .GetToken (ctx , registry , SchemeBasic , "" )
185
+ token , err := cache .GetToken (ctx , host , SchemeBasic , "" )
186
186
if err == nil {
187
187
req .Header .Set ("Authorization" , "Basic " + token )
188
188
}
189
189
case SchemeBearer :
190
- scopes := GetScopes (ctx )
190
+ scopes := GetAllScopesForHost (ctx , host )
191
191
attemptedKey = strings .Join (scopes , " " )
192
- token , err := cache .GetToken (ctx , registry , SchemeBearer , attemptedKey )
192
+ token , err := cache .GetToken (ctx , host , SchemeBearer , attemptedKey )
193
193
if err == nil {
194
194
req .Header .Set ("Authorization" , "Bearer " + token )
195
195
}
@@ -211,8 +211,8 @@ func (c *Client) Do(originalReq *http.Request) (*http.Response, error) {
211
211
case SchemeBasic :
212
212
resp .Body .Close ()
213
213
214
- token , err := cache .Set (ctx , registry , SchemeBasic , "" , func (ctx context.Context ) (string , error ) {
215
- return c .fetchBasicAuth (ctx , registry )
214
+ token , err := cache .Set (ctx , host , SchemeBasic , "" , func (ctx context.Context ) (string , error ) {
215
+ return c .fetchBasicAuth (ctx , host )
216
216
})
217
217
if err != nil {
218
218
return nil , fmt .Errorf ("%s %q: %w" , resp .Request .Method , resp .Request .URL , err )
@@ -223,17 +223,17 @@ func (c *Client) Do(originalReq *http.Request) (*http.Response, error) {
223
223
case SchemeBearer :
224
224
resp .Body .Close ()
225
225
226
- // merge hinted scopes with challenged scopes
227
- scopes := GetScopes ( ctx )
228
- if scope := params [ "scope" ]; scope != "" {
229
- scopes = append (scopes , strings .Split (scope , " " )... )
226
+ scopes := GetAllScopesForHost ( ctx , host )
227
+ if paramScope := params [ "scope" ]; paramScope != "" {
228
+ // merge hinted scopes with challenged scopes
229
+ scopes = append (scopes , strings .Split (paramScope , " " )... )
230
230
scopes = CleanScopes (scopes )
231
231
}
232
232
key := strings .Join (scopes , " " )
233
233
234
234
// attempt the cache again if there is a scope change
235
235
if key != attemptedKey {
236
- if token , err := cache .GetToken (ctx , registry , SchemeBearer , key ); err == nil {
236
+ if token , err := cache .GetToken (ctx , host , SchemeBearer , key ); err == nil {
237
237
req = originalReq .Clone (ctx )
238
238
req .Header .Set ("Authorization" , "Bearer " + token )
239
239
if err := rewindRequestBody (req ); err != nil {
@@ -254,8 +254,8 @@ func (c *Client) Do(originalReq *http.Request) (*http.Response, error) {
254
254
// attempt with credentials
255
255
realm := params ["realm" ]
256
256
service := params ["service" ]
257
- token , err := cache .Set (ctx , registry , SchemeBearer , key , func (ctx context.Context ) (string , error ) {
258
- return c .fetchBearerToken (ctx , registry , realm , service , scopes )
257
+ token , err := cache .Set (ctx , host , SchemeBearer , key , func (ctx context.Context ) (string , error ) {
258
+ return c .fetchBearerToken (ctx , host , realm , service , scopes )
259
259
})
260
260
if err != nil {
261
261
return nil , fmt .Errorf ("%s %q: %w" , resp .Request .Method , resp .Request .URL , err )
0 commit comments